2009-11-29 03:22:36 +00:00
|
|
|
#include <config.h>
|
2005-03-12 22:11:18 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2007-06-11 21:36:57 +00:00
|
|
|
#include <stasis/transactional.h>
|
2005-03-12 22:11:18 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
int max_active = 0;
|
|
|
|
|
|
|
|
pthread_mutex_t mutex;
|
|
|
|
|
|
|
|
//static pthread_mutex_t hash_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
static int count;
|
|
|
|
static recordid hash;
|
|
|
|
|
|
|
|
static void * go (void * arg_ptr) {
|
|
|
|
|
|
|
|
pthread_mutex_lock(&mutex);
|
|
|
|
i++;
|
|
|
|
if(i > max_active) {
|
|
|
|
max_active = i;
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&mutex);
|
|
|
|
|
|
|
|
// pthread_mutex_lock(&hash_mutex);
|
|
|
|
|
|
|
|
int k = *(int*)arg_ptr;
|
|
|
|
int j;
|
|
|
|
int xid = Tbegin();
|
|
|
|
|
|
|
|
unsigned int seed = k;
|
|
|
|
|
|
|
|
for(j = 0; j < count ; j++) {
|
|
|
|
unsigned int r = rand_r(&seed) % 10000;
|
2006-05-25 22:50:52 +00:00
|
|
|
byte * tmp = NULL;
|
|
|
|
ThashLookup(xid, hash, (byte*)&r, sizeof(int), &tmp);
|
|
|
|
assert(r == *(unsigned int*)tmp);
|
2005-03-12 22:11:18 +00:00
|
|
|
}
|
|
|
|
// for(j = k * count; j < (k+1) *(count) ; j++) {
|
|
|
|
// TlogicalHashInsert(xid, hash, &j, sizeof(int), &j, sizeof(int));
|
|
|
|
// printf("(%d)", k);
|
|
|
|
//}
|
|
|
|
|
|
|
|
Tcommit(xid);
|
|
|
|
/*
|
|
|
|
for(j = k * count; j < (k+1) *(count) ; j++) {
|
|
|
|
int tmp = -100;
|
|
|
|
TlogicalHashLookup(xid, hash, &j, sizeof(int), &tmp, sizeof(int));
|
|
|
|
assert(j == tmp);
|
|
|
|
} */
|
|
|
|
|
|
|
|
|
|
|
|
// pthread_mutex_unlock(&hash_mutex);
|
|
|
|
|
|
|
|
pthread_mutex_lock(&mutex);
|
|
|
|
i--;
|
|
|
|
pthread_mutex_unlock(&mutex);
|
|
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
|
|
|
|
assert(argc == 3);
|
|
|
|
|
|
|
|
int thread_count = atoi(argv[1]);
|
|
|
|
count = atoi(argv[2]);
|
|
|
|
|
|
|
|
/* unlink("storefile.txt");
|
|
|
|
unlink("logfile.txt");
|
|
|
|
unlink("blob0_file.txt");
|
|
|
|
unlink("blob1_file.txt");*/
|
|
|
|
|
2012-12-01 01:15:03 +00:00
|
|
|
pthread_t * workers = stasis_malloc(thread_count, pthread_t);
|
2005-03-12 22:11:18 +00:00
|
|
|
|
|
|
|
Tinit();
|
|
|
|
int xid = Tbegin();
|
2005-03-20 05:17:25 +00:00
|
|
|
// hash = ThashCreate(xid, sizeof(int), sizeof(int));
|
|
|
|
hash = ThashCreate(xid, VARIABLE_LENGTH, VARIABLE_LENGTH);
|
2005-03-12 22:11:18 +00:00
|
|
|
|
|
|
|
int k;
|
|
|
|
|
|
|
|
for(k = 0; k < 20000; k++) {
|
|
|
|
ThashInsert(xid, hash, (byte*)&k, sizeof(int), (byte*)&k, sizeof(int));
|
|
|
|
}
|
|
|
|
|
|
|
|
Tcommit(xid);
|
|
|
|
|
|
|
|
/* threads have static thread sizes. Ughh. */
|
|
|
|
pthread_attr_t attr;
|
|
|
|
pthread_attr_init(&attr);
|
|
|
|
|
|
|
|
pthread_mutex_init(&mutex, NULL);
|
|
|
|
|
|
|
|
pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN);
|
|
|
|
|
|
|
|
pthread_mutex_lock(&mutex);
|
|
|
|
|
|
|
|
for(k = 0; k < thread_count; k++) {
|
2012-12-01 01:15:03 +00:00
|
|
|
int * k_copy = stasis_alloc(int);
|
2005-03-12 22:11:18 +00:00
|
|
|
*k_copy = k ;
|
|
|
|
pthread_create(&workers[k], &attr, go, k_copy);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&mutex);
|
|
|
|
|
|
|
|
|
|
|
|
for(k = 0; k < thread_count; k++) {
|
|
|
|
pthread_join(workers[k],NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
Tdeinit();
|
|
|
|
|
|
|
|
printf("Max active at once: %d\n", max_active);
|
|
|
|
|
|
|
|
}
|