10 #define NUM_ITERATIONS 10000000
12 static volatile int wait_;
13 static long num_threads_;
14 static skiplist_t *sl_;
16 void *worker (void *arg) {
18 // Wait for all the worker threads to be ready.
22 for (int i = 0; i < NUM_ITERATIONS/num_threads_; ++i) {
23 unsigned r = nbd_rand();
24 uint64_t key = r & 0xF;
27 sprintf(key_str, "%llX", key);
29 sl_add(sl_, key_str, strlen(key_str) + 1, 1);
31 sl_remove(sl_, key_str, strlen(key_str) + 1);
35 sl_add(sl_, (void *)key, -1, 1);
37 sl_remove(sl_, (void *)key, -1);
47 int main (int argc, char **argv) {
49 //lwt_set_trace_level("s3");
51 char* program_name = argv[0];
52 pthread_t thread[MAX_NUM_THREADS];
55 fprintf(stderr, "Usage: %s num_threads\n", program_name);
63 num_threads_ = strtol(argv[1], NULL, 10);
65 fprintf(stderr, "%s: Invalid argument for number of threads\n", program_name);
68 if (num_threads_ <= 0) {
69 fprintf(stderr, "%s: Number of threads must be at least 1\n", program_name);
72 if (num_threads_ > MAX_NUM_THREADS) {
73 fprintf(stderr, "%s: Number of threads cannot be more than %d\n", program_name, MAX_NUM_THREADS);
80 struct timeval tv1, tv2;
81 gettimeofday(&tv1, NULL);
85 for (int i = 0; i < num_threads_; ++i) {
86 int rc = nbd_thread_create(thread + i, i, worker, (void*)(size_t)i);
87 if (rc != 0) { perror("pthread_create"); return rc; }
90 for (int i = 0; i < num_threads_; ++i) {
91 pthread_join(thread[i], NULL);
94 gettimeofday(&tv2, NULL);
95 int ms = (int)(1000000*(tv2.tv_sec - tv1.tv_sec) + tv2.tv_usec - tv1.tv_usec) / 1000;
97 printf("Th:%ld Time:%dms\n", num_threads_, ms);