2010-01-21 00:03:17 +00:00
|
|
|
#include <stasis/transactional.h>
|
2004-10-20 06:21:21 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
static pthread_mutex_t hash_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
static int count;
|
|
|
|
static recordid hash;
|
|
|
|
|
|
|
|
static void * go (void * arg_ptr) {
|
|
|
|
pthread_mutex_lock(&hash_mutex);
|
|
|
|
|
|
|
|
int k = *(int*)arg_ptr;
|
|
|
|
int j;
|
|
|
|
int xid = Tbegin();
|
|
|
|
|
|
|
|
for(j = k * count; j < (k+1) *(count) ; j++) {
|
2005-01-10 03:02:02 +00:00
|
|
|
TnaiveHashInsert(xid, hash, &j, sizeof(int), &j, sizeof(int));
|
2004-10-20 06:21:21 +00:00
|
|
|
// printf("(%d)", k);
|
|
|
|
}
|
|
|
|
|
|
|
|
Tcommit(xid);
|
|
|
|
pthread_mutex_unlock(&hash_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");
|
|
|
|
|
|
|
|
pthread_t * workers = malloc(sizeof(pthread_t) * thread_count);
|
|
|
|
|
|
|
|
Tinit();
|
|
|
|
int xid = Tbegin();
|
2008-11-03 21:42:42 +00:00
|
|
|
hash = TnaiveHashCreate(xid, sizeof(int), sizeof(int));
|
2004-10-20 06:21:21 +00:00
|
|
|
|
|
|
|
Tcommit(xid);
|
|
|
|
|
|
|
|
int k;
|
|
|
|
|
|
|
|
for(k = 0; k < thread_count; k++) {
|
|
|
|
int * k_copy = malloc(sizeof(int));
|
|
|
|
*k_copy = k ;
|
|
|
|
pthread_create(&workers[k], NULL, go, k_copy);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for(k = 0; k < thread_count; k++) {
|
|
|
|
pthread_join(workers[k],NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Tdeinit() */
|
|
|
|
}
|