diff options
author | Klaus Schmidinger <vdr@tvdr.de> | 2004-11-20 16:27:18 +0100 |
---|---|---|
committer | Klaus Schmidinger <vdr@tvdr.de> | 2004-11-20 16:27:18 +0100 |
commit | c33dccf9ba217add7e1dcfe8f8a4ea4fafb81008 (patch) | |
tree | 2dd1f6176e5711efc723b8b70962d5e9bd44e394 /thread.c | |
parent | ba85b34c62bfbd2067edf9918832309c441b2389 (diff) | |
download | vdr-c33dccf9ba217add7e1dcfe8f8a4ea4fafb81008.tar.gz vdr-c33dccf9ba217add7e1dcfe8f8a4ea4fafb81008.tar.bz2 |
Fixed handling childTid in cThread to avoid possible race conditions
Diffstat (limited to 'thread.c')
-rw-r--r-- | thread.c | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: thread.c 1.36 2004/10/31 09:54:02 kls Exp $ + * $Id: thread.c 1.37 2004/11/20 16:21:14 kls Exp $ */ #include "thread.h" @@ -233,12 +233,15 @@ void *cThread::StartThread(cThread *Thread) bool cThread::Start(void) { + Lock(); if (!childTid) { parentTid = pthread_self(); - pthread_create(&childTid, NULL, (void *(*) (void *))&StartThread, (void *)this); - pthread_detach(childTid); // auto-reap - pthread_setschedparam(childTid, SCHED_RR, 0); + pthread_t Tid; + pthread_create(&Tid, NULL, (void *(*) (void *))&StartThread, (void *)this); + pthread_detach(Tid); // auto-reap + pthread_setschedparam(Tid, SCHED_RR, 0); } + Unlock(); return true; //XXX return value of pthread_create()??? } @@ -277,10 +280,12 @@ void cThread::Cancel(int WaitSeconds) } esyslog("ERROR: thread %ld won't end (waited %d seconds) - cancelling it...", childTid, WaitSeconds); } + Lock(); if (childTid) { pthread_cancel(childTid); childTid = 0; } + Unlock(); } } |