Fix waiter list
authorweiyu <weiyuluo1232@gmail.com>
Mon, 6 Apr 2020 19:49:48 +0000 (12:49 -0700)
committerweiyu <weiyuluo1232@gmail.com>
Mon, 6 Apr 2020 19:49:48 +0000 (12:49 -0700)
execution.cc

index d455b51..48c73cf 100644 (file)
@@ -401,8 +401,17 @@ bool ModelExecution::process_mutex(ModelAction *curr)
                        /* unlock the lock - after checking who was waiting on it */
                        state->locked = NULL;
 
-                       /* disable this thread */
-                       get_safe_ptr_action(&condvar_waiters_map, curr->get_location())->push_back(curr);
+                       /* remove old wait action and disable this thread */
+                       action_list_t * waiters = get_safe_ptr_action(&condvar_waiters_map, curr->get_location());
+                       for (sllnode<ModelAction *> * it = waiters->begin(); it != NULL; it = it->getNext()) {
+                               ModelAction * wait = it->getVal();
+                               if (wait->get_tid() == curr->get_tid()) {
+                                       waiters->erase(it);
+                                       break;
+                               }
+                       }
+
+                       waiters->push_back(curr);
                        scheduler->sleep(get_thread(curr));
                }