edits
[model-checker-benchmarks.git] / concurrent-hashmap / main.cc
1 #include <iostream>
2 #include <threads.h>
3 #include "hashmap.h"
4
5 HashMap *table;
6
7 Key *k1, *k2;
8 Value *r1, *r2, *r3, *r4, *v1, *v2;
9
10 void printKey(Key *key) {
11         if (key)
12                 printf("pos = (%d, %d, %d)\n", key->x, key->y, key->z);
13         else
14                 printf("pos = NULL\n");
15 }
16
17 void printValue(Value *value) {
18         if (value)
19                 printf("velocity = (%d, %d, %d)\n", value->vX, value->vY, value->vZ);
20         else
21                 printf("velocity = NULL\n");
22 }
23
24 void threadA(void *arg) {
25         k1 = new Key(1, 1, 1);
26         k2 = new Key(3, 4, 5);
27         v1 = new Value(10, 10, 10);
28         r1 = table->put(k1, v1);
29         //printValue(r1);
30         r2 = table->get(k2);
31         printf("Thrd A:\n");
32         printValue(r2);
33 }
34
35 void threadB(void *arg) {
36         k1 = new Key(1, 1, 1);
37         k2 = new Key(3, 4, 5);
38         v2 = new Value(30, 40, 50);
39         r3 = table->put(k2, v2);
40         //printValue(r3);
41         r4 = table->get(k1);
42         printf("Thrd B:\n");
43         printValue(r4);
44 }
45
46 int user_main(int argc, char *argv[]) {
47         thrd_t t1, t2;
48         table = new HashMap;
49
50         thrd_create(&t1, threadA, NULL);
51         thrd_create(&t2, threadB, NULL);
52         thrd_join(t1);
53         thrd_join(t2);
54         
55         return 0;
56 }
57
58