From: Brian Norris Date: Thu, 6 Sep 2012 20:17:06 +0000 (-0700) Subject: threads: add a wait_list X-Git-Tag: pldi2013~235^2^2~7 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=d3b710fc183b8b71ab4726c2ae1b75caf13012b7;p=model-checker.git threads: add a wait_list This list will contain all Threads that are waiting on the current Thread. Will be used for Thread joins, in particular. --- diff --git a/threads.cc b/threads.cc index a939592..7fa4507 100644 --- a/threads.cc +++ b/threads.cc @@ -123,6 +123,7 @@ Thread::Thread(thrd_t *t, void (*func)(void *), void *a) : arg(a), user_thread(t), state(THREAD_CREATED), + wait_list(), last_action_val(VALUE_NONE) { int ret; diff --git a/threads.h b/threads.h index f7efcf9..25b1d64 100644 --- a/threads.h +++ b/threads.h @@ -7,6 +7,7 @@ #include #include +#include #include "mymemory.h" #include "libthreads.h" @@ -70,6 +71,25 @@ public: /** @return True if this thread is finished executing */ bool is_complete() { return state == THREAD_COMPLETED; } + /** @return True if no threads are waiting on this Thread */ + bool wait_list_empty() { return wait_list.empty(); } + + /** + * Add a thread to the waiting list for this thread. + * @param t The Thread to add + */ + void push_wait_list(Thread *t) { wait_list.push_back(t); } + + /** + * Remove one Thread from the waiting list + * @return The Thread that was removed from the waiting list + */ + Thread * pop_wait_list() { + Thread *ret = wait_list.front(); + wait_list.pop_back(); + return ret; + } + friend void thread_startup(); SNAPSHOTALLOC @@ -86,6 +106,13 @@ private: thread_id_t id; thread_state state; + /** + * A list of Threads waiting on this Thread. Particularly, this list is + * used for thread joins, where another Thread waits for this Thread to + * complete + */ + std::vector wait_list; + /** * The value returned by the last action in this thread * @see Thread::set_return_value()