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