fixed mpmc spec
[cdsspec-compiler.git] / benchmark / cliffc-hashtable / main.cc
index 7641fc0a4b7d7cb1da9c47110828591ffb1ddac3..cadedced0087ff17124635699f29dea26eb8b5d3 100644 (file)
@@ -45,33 +45,73 @@ class IntWrapper {
                }
 };
 
-
-cliffc_hashtable<IntWrapper, IntWrapper> table;
-IntWrapper *val;
+cliffc_hashtable<IntWrapper, IntWrapper> *table;
+IntWrapper *val1, *val2;
 
 void threadA(void *arg) {
-       IntWrapper k1(3), k2(4), v1(1), v2(2);
-       table.put(k1, v1);
-       table.put(k2, v2);
+       /*
+       IntWrapper k1(3), k2(5), k3(1024), k4(1025);
+       IntWrapper v1(1), v2(2), v3(73), v4(81);
+       table->put(k1, v1);
+       table->put(k2, v2);
+       val1 = table->get(k3);
+       table->put(k3, v3);
+       */
+       for (int i = 200; i < 205; i++) {
+               IntWrapper k(i), v(i * 2);
+               table->put(k, v);
+       }
 }
 
 void threadB(void *arg) {
-       IntWrapper k1(3), k2(4), v1(1), v2(2);
-       val = table.get(k2);
+       IntWrapper k1(3), k2(5), k3(1024), k4(1025);
+       IntWrapper v1(1), v2(2), v3(73), v4(81);
+       table->put(k1, v3);
+       table->put(k2, v4);
+       val1 = table->get(k2);
+}
+
+void threadC(void *arg) {
+       IntWrapper k1(3), k2(5), k3(1024), k4(1025);
+       IntWrapper v1(1), v2(2), v3(73), v4(81);
+       table->put(k1, v1);
+       table->put(k2, v2);
+       val2 = table->get(k1);
+}
+
+void threadD(void *arg) {
+       IntWrapper k1(3), k2(5), k3(1024), k4(1025);
+       IntWrapper v1(1), v2(2), v3(73), v4(81);
+       table->put(k1, v2);
+       table->put(k2, v1);
+       val2 = table->get(k2);
 }
 
 int user_main(int argc, char *argv[]) {
-       thrd_t t1, t2;
-       val = new IntWrapper(0);
+       thrd_t t1, t2, t3, t4;
+       table = new cliffc_hashtable<IntWrapper, IntWrapper>();
+       val1 = NULL;
+       val2 = NULL;
        thrd_create(&t1, threadA, NULL);
        thrd_create(&t2, threadB, NULL);
+       thrd_create(&t3, threadC, NULL);
+       //thrd_create(&t4, threadD, NULL);
 
        thrd_join(t1);
-       thrd_join(t2);/*
-       if (val == NULL) {
-               cout << "NULL" << endl;
+       thrd_join(t2);
+       thrd_join(t3);
+       //thrd_join(t4);
+       
+       if (val1 == NULL) {
+               cout << "val1: NULL" << endl;
+       } else {
+               cout << val1->get() << endl;
+       }
+       MODEL_ASSERT(val1 == NULL || val1->get() == 2 || val1->get() == 81);
+       if (val2 == NULL) {
+               cout << "val2: NULL" << endl;
        } else {
-               cout << val->get() << endl;
-       }*/
+               cout << val2->get() << endl;
+       }
        return 0;
 }