From c27c32fcf90773a9468cd827d9e118630dd51e87 Mon Sep 17 00:00:00 2001 From: Ho-Eun Ryu Date: Fri, 25 Sep 2009 14:53:52 +0900 Subject: utils:thread: fix bug, pthread create/join this patch prevent Start() from creating new thread without Join() and join() from joining a thread not created yet. --- utils/src/thread.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'utils/src') diff --git a/utils/src/thread.cpp b/utils/src/thread.cpp index 9b096c4..17f70d9 100644 --- a/utils/src/thread.cpp +++ b/utils/src/thread.cpp @@ -4,6 +4,7 @@ Thread::Thread() { r = NULL; + created = false; } Thread::Thread(RunnableInterface *r) @@ -18,12 +19,27 @@ Thread::~Thread() int Thread::Start(void) { - return pthread_create(&id, NULL, Instance, this); + int ret = 0; + + if (!created) { + ret = pthread_create(&id, NULL, Instance, this); + if (!ret) + created = true; + } + + return ret; } int Thread::Join(void) { - return pthread_join(id, NULL); + int ret = 0; + + if (created) { + ret = pthread_join(id, NULL); + created = false; + } + + return ret; } void *Thread::Instance(void *p) -- cgit v1.2.3