Fix a bug
[c11tester.git] / newfuzzer.cc
index 69f1ce148bb3c2eb70f2252c1f8cba07b7722888..6810d022a990fc6f50765a653b21ce2de5bc2745 100644 (file)
@@ -17,7 +17,7 @@ NewFuzzer::NewFuzzer() :
        thrd_curr_pred(),
        thrd_selected_child_branch(),
        thrd_pruned_writes(),
-       paused_thread_set(),
+       paused_thread_list(),
        paused_thread_table(128)
 {}
 
@@ -65,8 +65,6 @@ int NewFuzzer::selectWrite(ModelAction *read, SnapVector<ModelAction *> * rf_set
 
                conditional_sleep(read_thread);
 
-               find_threads(read);
-
                return -1;
 /*
                SnapVector<ModelAction *> * pruned_writes = thrd_pruned_writes[thread_id];
@@ -212,10 +210,10 @@ bool NewFuzzer::prune_writes(thread_id_t tid, Predicate * pred,
  */
 void NewFuzzer::conditional_sleep(Thread * thread)
 {
-       int index = paused_thread_set.size();
+       int index = paused_thread_list.size();
 
        model->getScheduler()->add_sleep(thread);
-       paused_thread_set.push_back(thread);
+       paused_thread_list.push_back(thread);
        paused_thread_table.put(thread, index); // Update table
 
        /* Add the waiting condition to ModelHistory */
@@ -229,18 +227,21 @@ void NewFuzzer::conditional_sleep(Thread * thread)
        concrete->set_location(read->get_location());
 
        history->add_waiting_write(concrete);
+
+       /* history->add_waiting_thread is called in find_threads */
+       find_threads(read);
 }
 
 bool NewFuzzer::has_paused_threads()
 {
-       return paused_thread_set.size() != 0;
+       return paused_thread_list.size() != 0;
 }
 
 Thread * NewFuzzer::selectThread(int * threadlist, int numthreads)
 {
        if (numthreads == 0 && has_paused_threads()) {
                wake_up_paused_threads(threadlist, &numthreads);
-               model_print("list size: %d, active t id: %d\n", numthreads, threadlist[0]);
+               //model_print("list size: %d, active t id: %d\n", numthreads, threadlist[0]);
        }
 
        int random_index = random() % numthreads;
@@ -254,18 +255,19 @@ Thread * NewFuzzer::selectThread(int * threadlist, int numthreads)
  */
 void NewFuzzer::wake_up_paused_threads(int * threadlist, int * numthreads)
 {
-       int random_index = random() % paused_thread_set.size();
-       Thread * thread = paused_thread_set[random_index];
+       int random_index = random() % paused_thread_list.size();
+       Thread * thread = paused_thread_list[random_index];
        model->getScheduler()->remove_sleep(thread);
 
-       Thread * last_thread = paused_thread_set.back();
-       paused_thread_set[random_index] = last_thread;
-       paused_thread_set.pop_back();
+       Thread * last_thread = paused_thread_list.back();
+       paused_thread_list[random_index] = last_thread;
+       paused_thread_list.pop_back();
        paused_thread_table.put(last_thread, random_index);     // Update table
        paused_thread_table.remove(thread);
 
        thread_id_t tid = thread->get_id();
        history->remove_waiting_write(tid);
+       history->remove_waiting_thread(tid);
 
        model_print("thread %d is woken up\n", tid);
        threadlist[*numthreads] = tid;
@@ -280,19 +282,22 @@ void NewFuzzer::notify_paused_thread(Thread * thread)
        int index = paused_thread_table.get(thread);
        model->getScheduler()->remove_sleep(thread);
 
-       Thread * last_thread = paused_thread_set.back();
-       paused_thread_set[index] = last_thread;
-       paused_thread_set.pop_back();
+       Thread * last_thread = paused_thread_list.back();
+       paused_thread_list[index] = last_thread;
+       paused_thread_list.pop_back();
        paused_thread_table.put(last_thread, index);    // Update table
        paused_thread_table.remove(thread);
 
        thread_id_t tid = thread->get_id();
        history->remove_waiting_write(tid);
+       history->remove_waiting_thread(tid);
 }
 
 /* Find threads that may write values that the pending read action is waiting for */
 void NewFuzzer::find_threads(ModelAction * pending_read)
 {
+       ASSERT(pending_read->is_read());
+
        void * location = pending_read->get_location();
        thread_id_t self_id = pending_read->get_tid();
 
@@ -311,7 +316,7 @@ void NewFuzzer::find_threads(ModelAction * pending_read)
 
                        int distance = node->compute_distance(target_node);
                        if (distance != -1) {
-                               history->add_waiting_thread(self_id, tid, distance);
+                               history->add_waiting_thread(self_id, tid, target_node, distance);
                                model_print("thread: %d; distance from node %d to node %d: %d\n", tid, node->get_func_id(), target_node->get_func_id(), distance);
 
                        }