Implement both pthread_yield and c++ thread yield
[c11tester.git] / model.cc
index 4c4b47ac4c12e466bbe4d03b687a9a3f5debf113..cffaea874740ada79a5ee89e0901e31e9dbcdb2c 100644 (file)
--- a/model.cc
+++ b/model.cc
@@ -413,7 +413,7 @@ void ModelChecker::run()
                        for (unsigned int i = 0;i < get_num_threads();i++) {
                                thread_id_t tid = int_to_id(i);
                                Thread *thr = get_thread(tid);
-                               if (!thr->is_model_thread() && !thr->is_complete() && (!thr->get_pending())) {
+                               if (!thr->is_model_thread() && !thr->is_complete() && !thr->get_pending()) {
                                        switch_from_master(thr);
                                        if (thr->is_waiting_on(thr))
                                                assert_bug("Deadlock detected (thread %u)", i);
@@ -459,6 +459,12 @@ void ModelChecker::run()
                                t = get_next_thread();
                        if (!t || t->is_model_thread())
                                break;
+                       if (t->just_woken_up()) {
+                               t->set_wakeup_state(false);
+                               t->set_pending(NULL);
+                               t = NULL;
+                               continue;       // Allow this thread to stash the next pending action
+                       }
 
                        /* Consume the next action for a Thread */
                        ModelAction *curr = t->get_pending();