#include <iostream>
#include <atomic>
+#include "stdio.h"
//#include <common.h>
#ifdef STANDALONE
#include <assert.h>
/**
@Begin
@Interface: Get
- //@Commit_point_set: Get_Point1 | Get_Point2 | Get_Point3 | Get_ReadKVS
- @Commit_point_set: Get_Point1 | Get_Point2 | Get_Point3
+ //@Commit_point_set: Get_Point1 | Get_Point2 | Get_ReadKVS | Get_ReadNewKVS | Get_Clear
+ @Commit_point_set: Get_Point1 | Get_Point2 | Get_Clear
+ //@Commit_point_set: Get_Point1 | Get_Point2 | Get_Point3
@ID: getKeyTag(key)
@Action:
TypeV *_Old_Val = (TypeV*) spec_table_get(map, key);
/**
@Begin
@Interface: Put
- @Commit_point_set: Put_Point
+ //@Commit_point_set: Put_Point | Put_ReadKVS | Put_ReadNewKVS | Put_WriteKey
+ @Commit_point_set: Put_Point | Put_WriteKey
@ID: getKeyTag(key)
@Action:
# Remember this old value at checking point
if (keyeq(K, key_slot, hashes, idx, fullhash)) {
// Key hit! Check if table-resize in progress
if (!is_prime(V)) {
+ /**
+ @Begin
+ @Commit_point_clear: true
+ @Label: Get_Clear
+ @End
+ */
+
/**
@Begin
@Commit_point_define: true
/**** FIXME: miss ****/
kvs_data *newkvs = chm->_newkvs.load(memory_order_acquire);
/**
- @Begin
- @Commit_point_define_check: newkvs == NULL
- @Label: Get_Point3
+ //@Begin
+ @Commit_point_define_check: true
+ @Label: Get_ReadNewKVS
@End
*/
return newkvs == NULL ? NULL : get_impl(topmap,
if (val_slot == TOMBSTONE) return val_slot;
// Claim the null key-slot
if (CAS_key(kvs, idx, NULL, key_slot)) {
+ /**
+ @Begin
+ @Commit_point_define: true
+ @Potential_commit_point_label: Write_Key_Point
+ @Label: Put_WriteKey
+ @End
+ */
chm->_slots.fetch_add(1, memory_order_relaxed); // Inc key-slots-used count
hashes[idx] = fullhash; // Memorize full hash
break;
// its progress (eagerly try to resize soon)
/**** FIXME: miss ****/
newkvs = chm->_newkvs.load(memory_order_acquire);
+ /**
+ //@Begin
+ @Commit_point_define_check: true
+ @Label: Put_ReadNewKVS
+ @End
+ */
if (newkvs == NULL &&
((V == NULL && chm->table_full(reprobe_cnt, len)) || is_prime(V))) {
//model_print("resize2\n");
IntWrapper *v0, *v1, *v2, *v3, *v4, *v5;
void threadA(void *arg) {
- table->put(k1, v4);
- table->put(k3, v3);
- //table->put(k2, v2);
- //table->put(k3, v3);
- /*
- val1 = table->get(k3);
- if (val1 != NULL)
- model_print("val1: %d\n", val1->_val);
- else
- model_print("val1: NULL\n");*/
- //table->put(k3, v3);
-
+ table->put(k3, v3);
+ val1 = table->get(k2);
+
+
}
void threadB(void *arg) {
- //table->put(k1, v1);
- //table->put(k2, v4);
- //table->put(k3, v3);
-}
+ }
void threadMain(void *arg) {
- val1 = table->get(k1);
- //val2 = table->get(k2);
- /*
- if (val1 != NULL)
- model_print("val1: %d\n", val1->_val);
- else
- model_print("val1: NULL\n");
- if (val2 != NULL)
- model_print("val2: %d\n", val2->_val);
- else
- model_print("val2: NULL\n");*/
+ table->put(k2, v2);
+ val1 = table->get(k3);
+
}
int user_main(int argc, char *argv[]) {
thrd_t t1, t2;
- table = new cliffc_hashtable<IntWrapper, IntWrapper>(2);
+ table = new cliffc_hashtable<IntWrapper, IntWrapper>(32);
k1 = new IntWrapper(3);
k2 = new IntWrapper(5);
k3 = new IntWrapper(11);
v5 = new IntWrapper(99);
v0 = new IntWrapper(2048);
- table->put(k1, v0);
- table->put(k2, v0);
- //model_print("hey\n");
- thrd_create(&t1, threadA, NULL);
+ thrd_create(&t1, threadA, NULL);
thrd_create(&t2, threadB, NULL);
threadMain(NULL);
thrd_join(t1);
thrd_join(t2);
- /*
- 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 << val2->get() << endl;
- }
- */
+
return 0;
}
+
--- /dev/null
+#include <iostream>
+#include <threads.h>
+#include "cliffc_hashtable.h"
+
+using namespace std;
+
+template<typename TypeK, typename TypeV>
+slot* const cliffc_hashtable<TypeK, TypeV>::MATCH_ANY = new slot(false, NULL);
+
+template<typename TypeK, typename TypeV>
+slot* const cliffc_hashtable<TypeK, TypeV>::NO_MATCH_OLD = new slot(false, NULL);
+
+template<typename TypeK, typename TypeV>
+slot* const cliffc_hashtable<TypeK, TypeV>::TOMBPRIME = new slot(true, NULL);
+
+template<typename TypeK, typename TypeV>
+slot* const cliffc_hashtable<TypeK, TypeV>::TOMBSTONE = new slot(false, NULL);
+
+
+class IntWrapper {
+ private:
+ public:
+ int _val;
+
+ IntWrapper(int val) : _val(val) {}
+
+ IntWrapper() : _val(0) {}
+
+ IntWrapper(IntWrapper& copy) : _val(copy._val) {}
+
+ int get() {
+ return _val;
+ }
+
+ int hashCode() {
+ return _val;
+ }
+
+ bool operator==(const IntWrapper& rhs) {
+ return false;
+ }
+
+ bool equals(const void *another) {
+ if (another == NULL)
+ return false;
+ IntWrapper *ptr =
+ (IntWrapper*) another;
+ return ptr->_val == _val;
+ }
+};
+
+cliffc_hashtable<IntWrapper, IntWrapper> *table;
+IntWrapper *val1, *val2;
+IntWrapper *k0, *k1, *k2, *k3, *k4, *k5;
+IntWrapper *v0, *v1, *v2, *v3, *v4, *v5;
+
+void threadA(void *arg) {
+ //table->put(k1, v4);
+ table->put(k3, v3);
+ val1 = table->get(k2);
+ //table->put(k3, v3);
+ /*
+ val1 = table->get(k3);
+ if (val1 != NULL)
+ model_print("val1: %d\n", val1->_val);
+ else
+ model_print("val1: NULL\n");*/
+ //table->put(k3, v3);
+
+}
+
+void threadB(void *arg) {
+ //table->put(k1, v1);
+ //table->put(k2, v4);
+ //table->put(k3, v3);
+}
+
+void threadMain(void *arg) {
+ table->put(k2, v2);
+ val1 = table->get(k3);
+ //val2 = table->get(k2);
+ /*
+ if (val1 != NULL)
+ model_print("val1: %d\n", val1->_val);
+ else
+ model_print("val1: NULL\n");
+ if (val2 != NULL)
+ model_print("val2: %d\n", val2->_val);
+ else
+ model_print("val2: NULL\n");*/
+}
+
+int user_main(int argc, char *argv[]) {
+ thrd_t t1, t2;
+ table = new cliffc_hashtable<IntWrapper, IntWrapper>(32);
+ k1 = new IntWrapper(3);
+ k2 = new IntWrapper(5);
+ k3 = new IntWrapper(11);
+ k4 = new IntWrapper(7);
+ k5 = new IntWrapper(13);
+
+ v1 = new IntWrapper(1024);
+ v2 = new IntWrapper(47);
+ v3 = new IntWrapper(73);
+ v4 = new IntWrapper(81);
+ v5 = new IntWrapper(99);
+
+ v0 = new IntWrapper(2048);
+ //table->put(k1, v0);
+ //table->put(k2, v0);
+ //model_print("hey\n");
+ thrd_create(&t1, threadA, NULL);
+ thrd_create(&t2, threadB, NULL);
+ threadMain(NULL);
+
+ thrd_join(t1);
+ thrd_join(t2);
+ /*
+ 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 << val2->get() << endl;
+ }
+ */
+ return 0;
+}
+
if ((i % 2) == 0) {
read_lock(&mylock);
//load_32(&shareddata);
- printf("%d\n", shareddata);
+ //printf("%d\n", shareddata);
read_unlock(&mylock);
} else {
write_lock(&mylock);
for(i = 0; i < 2; i++) {
if ((i % 2) == 0) {
if (read_trylock(&mylock) == 1) {
- printf("%d\n", shareddata);
+ //printf("%d\n", shareddata);
read_unlock(&mylock);
}
} else {
if (write_trylock(&mylock) == 1) {
- shareddata = 47;
+ //shareddata = 47;
write_unlock(&mylock);
}
}
{
mcs_mutex::guard g(mutex);
//printf("store: %d\n", 17);
- store_32(&shared, 17);
- //shared = 17;
+ //store_32(&shared, 17);
+ shared = 17;
mutex->unlock(&g);
mutex->lock(&g);
//printf("load: %u\n", load_32(&shared));
mutex->unlock(&g);
mutex->lock(&g);
//printf("store: %d\n", 17);
- //shared = 17;
- store_32(&shared, 17);
+ shared = 17;
+ //store_32(&shared, 17);
}
int user_main(int argc, char **argv)
unsigned int in_sum = 0, out_sum = 0;
queue = calloc(1, sizeof(*queue));
- MODEL_ASSERT(queue);
+ //MODEL_ASSERT(queue);
num_threads = procs;
threads = malloc(num_threads * sizeof(thrd_t));
}
for (i = 0; i < num_threads; i++)
thrd_join(threads[i]);
-
+/*
for (i = 0; i < num_threads; i++) {
in_sum += input[i];
out_sum += output[i];
for (i = 0; i < num_threads; i++)
printf("output[%d] = %u\n", i, output[i]);
//MODEL_ASSERT(in_sum == out_sum);
+ */
free(param);
free(threads);
}
}
/* free_list is empty? */
- MODEL_ASSERT(0);
+ //MODEL_ASSERT(0);
return 0;
}
int t = get_thread_num();
/* Don't reclaim NULL node */
- MODEL_ASSERT(node);
+ //MODEL_ASSERT(node);
for (i = 0; i < MAX_FREELIST; i++) {
/* Should never race with our own thread here */
}
}
/* free list is full? */
- MODEL_ASSERT(0);
+ //MODEL_ASSERT(0);
}
void init_queue(queue_t *q, int num_threads)
tail = atomic_load_explicit(&q->tail, acquire);
/****FIXME: miss ****/
next = atomic_load_explicit(&q->nodes[get_ptr(tail)].next, acquire);
- printf("miss1_enqueue\n");
+ //printf("miss1_enqueue\n");
if (tail == atomic_load_explicit(&q->tail, relaxed)) {
/* Check for uninitialized 'next' */
succ = atomic_compare_exchange_strong_explicit(&q->tail,
&tail, value, release, relaxed);
if (succ) {
- printf("miss2_enqueue CAS succ\n");
+ //printf("miss2_enqueue CAS succ\n");
}
- printf("miss2_enqueue\n");
+ //printf("miss2_enqueue\n");
thrd_yield();
}
}
tail = atomic_load_explicit(&q->tail, relaxed);
/****FIXME: miss ****/
next = atomic_load_explicit(&q->nodes[get_ptr(head)].next, acquire);
- printf("miss3_dequeue\n");
+ //printf("miss3_dequeue\n");
if (atomic_load_explicit(&q->head, relaxed) == head) {
if (get_ptr(head) == get_ptr(tail)) {
/* Check for uninitialized 'next' */
- MODEL_ASSERT(get_ptr(next) != POISON_IDX);
+ //MODEL_ASSERT(get_ptr(next) != POISON_IDX);
if (get_ptr(next) == 0) { // NULL
/**
MAKE_POINTER(get_ptr(next), get_count(tail) + 1),
release, relaxed);
if (succ) {
- printf("miss4_dequeue CAS succ\n");
+ //printf("miss4_dequeue CAS succ\n");
}
- printf("miss4_dequeue\n");
+ //printf("miss4_dequeue\n");
thrd_yield();
} else {
value = load_32(&q->nodes[get_ptr(next)].value);