From: Brian Norris Date: Tue, 24 Apr 2012 02:22:52 +0000 (-0700) Subject: threads: save id within class Thread X-Git-Tag: pldi2013~516 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=a9aac0d43e0e24354af4163cd3161036586f029a;hp=067807af61c0df207b4ca77660eeb3b6e9e6882c;p=model-checker.git threads: save id within class Thread There may be points at which the user's thread ID struct goes out of scope, but I still need it internally. I think I'll just keep it internally, with a duplicate in the user's copy. --- diff --git a/model.cc b/model.cc index f3844f0..1f13de7 100644 --- a/model.cc +++ b/model.cc @@ -30,9 +30,9 @@ ModelChecker::~ModelChecker() delete rootNode; } -void ModelChecker::assign_id(Thread *t) +int ModelChecker::get_next_id() { - t->set_id(++used_thread_id); + return ++used_thread_id; } void ModelChecker::add_system_thread(Thread *t) diff --git a/model.h b/model.h index 7dbd9ab..64d052f 100644 --- a/model.h +++ b/model.h @@ -81,7 +81,7 @@ public: int add_thread(Thread *t); Thread * get_thread(thread_id_t tid) { return thread_map[tid]; } - void assign_id(Thread *t); + int get_next_id(); int switch_to_master(ModelAction *act); diff --git a/threads.cc b/threads.cc index 4c2086d..4c7ac41 100644 --- a/threads.cc +++ b/threads.cc @@ -73,7 +73,8 @@ Thread::Thread(thrd_t *t, void (*func)(), void *a) { printf("Error in create_context\n"); state = THREAD_CREATED; - model->assign_id(this); + id = model->get_next_id(); + *user_thread = id; model->scheduler->add_thread(this); } @@ -84,14 +85,15 @@ Thread::Thread(thrd_t *t) { arg = NULL; state = THREAD_CREATED; - model->assign_id(this); + id = model->get_next_id(); + *user_thread = id; create_context(); model->add_system_thread(this); } thread_id_t Thread::get_id() { - return thrd_to_id(*user_thread); + return id; } /* diff --git a/threads.h b/threads.h index 8e0c3b0..0c5fdab 100644 --- a/threads.h +++ b/threads.h @@ -24,7 +24,6 @@ public: thread_state get_state() { return state; } void set_state(thread_state s) { state = s; } thread_id_t get_id(); - void set_id(thread_id_t i) { *user_thread = i; } thrd_t get_thrd_t() { return *user_thread; } private: int create_context(); @@ -34,6 +33,7 @@ private: ucontext_t context; void *stack; thrd_t *user_thread; + thread_id_t id; thread_state state; };