+
+/* @brief Put a thread to sleep because no writes in rf_set satisfies the selected predicate.
+ *
+ * @param thread A thread whose last action is a read
+ */
+void NewFuzzer::conditional_sleep(Thread * thread)
+{
+ model->getScheduler()->add_sleep(thread);
+ paused_thread_set.push_back(thread);
+}
+
+bool NewFuzzer::has_paused_threads()
+{
+ return paused_thread_set.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\n", numthreads);
+ model_print("active t id: %d\n", threadlist[0]);
+ }
+
+ int random_index = random() % numthreads;
+ int thread = threadlist[random_index];
+ thread_id_t curr_tid = int_to_id(thread);
+ return model->get_thread(curr_tid);
+}
+
+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];
+ model->getScheduler()->remove_sleep(thread);
+
+ paused_thread_set[random_index] = paused_thread_set.back();
+ paused_thread_set.pop_back();
+
+ model_print("thread %d is woken up\n", thread->get_id());
+ threadlist[*numthreads] = thread->get_id();
+ (*numthreads)++;
+}