From: Brian Norris Date: Tue, 3 Jul 2012 23:31:45 +0000 (-0700) Subject: threads: add per-thread "return" values for 'model-checking/user context' switch X-Git-Tag: pldi2013~378 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=85c090982c2a8dd6e236aa8f3d0a79f974ab9603;p=model-checker.git threads: add per-thread "return" values for 'model-checking/user context' switch The model-checker needs to return a value to the user context when performing atomic loads, for instance. I will be implementing this by caching the return value on a per-thread basis. This is because an atomic_load() might result in a context switch before actually returning the value. These functions are not yet used. --- diff --git a/threads.cc b/threads.cc index 6d290a9..b6eaee4 100644 --- a/threads.cc +++ b/threads.cc @@ -69,7 +69,9 @@ void Thread::complete() } } -Thread::Thread(thrd_t *t, void (*func)(void *), void *a) { +Thread::Thread(thrd_t *t, void (*func)(void *), void *a) : + last_action_val(VALUE_NONE) +{ int ret; user_thread = t; diff --git a/threads.h b/threads.h index a97a04c..ed9cbfe 100644 --- a/threads.h +++ b/threads.h @@ -41,6 +41,21 @@ public: void set_creation(ModelAction *act) { creation = act; } ModelAction * get_creation() { return creation; } + /** + * Set a return value for the last action in this thread (e.g., for an + * atomic read). + * @param value The value to return + */ + void set_return_value(int value) { last_action_val = value; } + + /** + * Retrieve a return value for the last action in this thread. Used, + * for instance, for an atomic read to return the 'read' value. Should + * be called from a user context. + * @return The value 'returned' by the action + */ + int get_return_value() { return last_action_val; } + friend void thread_startup(); SNAPSHOTALLOC @@ -56,6 +71,13 @@ private: thrd_t *user_thread; thread_id_t id; thread_state state; + + /** + * The value returned by the last action in this thread + * @see Thread::set_return_value() + * @see Thread::get_return_value() + */ + int last_action_val; }; Thread * thread_current();