From 9d29a2cc48540d41e008b65174514cea44375090 Mon Sep 17 00:00:00 2001 From: rfm Date: Mon, 30 Aug 2010 19:16:30 +0000 Subject: [PATCH] locking tweak git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@31210 72102866-910b-0410-8b05-ffd578937521 --- Source/NSThread.m | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Source/NSThread.m b/Source/NSThread.m index 47c121261..32b0ae48f 100644 --- a/Source/NSThread.m +++ b/Source/NSThread.m @@ -919,11 +919,17 @@ static void *nsthreadLauncher(void* thread) NSLog(@"Set event failed - %@", [NSError _last]); } #else - /* The write could concievably fail if the pipe is full, but in that - * case we don't care since the other thread should be woken to handle - * reading anyway. + /* The write could concievably fail if the pipe is full. + * In that case we need to release the lock teporarily to allow the other + * thread to consume data from the pipe. It's possible that the thread + * and its runloop might stop during that ... so we need to check that + * outputFd is still valid. */ - write(outputFd, "0", 1); + while (outputFd >= 0 && write(outputFd, "0", 1) != 1) + { + [lock unlock]; + [lock lock]; + } #endif [lock unlock]; }