From 91844cc151ebe4111e5bb0080970ab56165d58fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Mon, 26 Oct 2009 19:28:14 +0000 Subject: [PATCH] Patch from Olivier Coursiere (ticket #4064): cond_wait always return EAGAIN with an unitialized pthread_cond_t git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33779 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/libroot/posix/pthread/pthread_cond.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/system/libroot/posix/pthread/pthread_cond.c b/src/system/libroot/posix/pthread/pthread_cond.c index b8a2be66df..112ba7a043 100644 --- a/src/system/libroot/posix/pthread/pthread_cond.c +++ b/src/system/libroot/posix/pthread/pthread_cond.c @@ -82,9 +82,11 @@ cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex, bigtime_t timeout) // Note, this is thread-safe, since another thread would be required to // hold the same mutex. sem_id sem = create_sem(0, "pthread_cond"); - if (cond->sem < 0) + if (sem < 0) return EAGAIN; - cond->sem = sem; + + if (atomic_test_and_set((vint32*)&cond->sem, sem, -42) != -42) + delete_sem(sem); } if (cond->mutex && cond->mutex != mutex)