From: Brian Norris Date: Fri, 9 Mar 2012 23:18:07 +0000 (-0800) Subject: libthreads: merge thread_create() and thread_start() X-Git-Tag: pldi2013~616 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=6ac83ab66e4c564ffd0470ad25d5554eb5d52f28;p=model-checker.git libthreads: merge thread_create() and thread_start() --- diff --git a/libthreads.c b/libthreads.c index c69e45a..bd7f501 100644 --- a/libthreads.c +++ b/libthreads.c @@ -86,6 +86,7 @@ static int master_thread_yield() int thread_create(struct thread *t, void (*start_routine), void *arg) { static int created = 1; + int ret = 0; DBG(); @@ -97,14 +98,12 @@ int thread_create(struct thread *t, void (*start_routine), void *arg) t->arg = arg; /* Initialize state */ - return create_context(t); -} - -void thread_start(struct thread *t) -{ - DBG(); + ret = create_context(t); + if (ret) + return ret; schedule_add_thread(t); + return 0; } void thread_join(struct thread *t) @@ -129,13 +128,10 @@ void user_main() struct thread t1, t2; int i = 2, j = 3; + printf("%s() creating 2 threads\n", __func__); thread_create(&t1, &a, &i); thread_create(&t2, &a, &j); - printf("%s() is going to start 1 thread\n", __func__); - thread_start(&t1); - thread_start(&t2); - thread_join(&t1); thread_join(&t2); printf("%s() is finished\n", __func__); @@ -149,7 +145,6 @@ int main() create_initial_thread(main_thread); thread_create(&user_thread, &user_main, NULL); - thread_start(&user_thread); /* Wait for all threads to complete */ while (master_thread_yield() == 0); diff --git a/libthreads.h b/libthreads.h index ff6d5aa..f8a86cd 100644 --- a/libthreads.h +++ b/libthreads.h @@ -22,6 +22,5 @@ struct thread { }; int thread_create(struct thread *t, void (*start_routine), void *arg); -void thread_start(struct thread *t); #endif /* __LIBTHREADS_H__ */