You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by INOUE Seiichiro <in...@ariel-networks.com> on 2003/07/10 18:06:03 UTC

Win32 apr_thread_cond_wait() has a mutex problem?

apr_thread_cond_wait()/apr_thread_cond_timedwait() on Win32 seem to have a mutex problem.


res = WaitForSingleObject(cond->event, INFINITE);
After this line, there is no mutex lock working, so 'cond->signalled' and 'cond->signal_all'
are not protected from other threads.
Therefore, the following problem could occur.


E.g.
There are 3 threads,
one of them is calling apr_thread_cond_wait(),  [thread-A]
two of them are calling apr_thread_cond_signal(). [thread-B,C]

thread-A's flow...
[1. thread-A is sleeping here]
res = WaitForSingleObject(cond->event, INFINITE);
[2. thered-A is waken up by thread-B. 
    thread-B: cond->signalled = 1 in apr_thread_cond_signal(), and exits from apr_thread_cond_signal()]
[3. task-switched to thread-A]
[snip]
if (cond->signalled) {
    [4. task-switched to thread-C. cond->signalled = 1 in apr_thread_cond_signal()]
    [5. task-switched to thread-A]
    cond->signalled = 0;
    ResetEvent(cond->event);
    [6. task-switched to thread-C. SetEvent(cond->event) in apr_thread_cond_signal()]
    break;
}

As a result, SetEvent(cond->event) and cond->signalled = 0 are completed.
It causes an infinite loop in a next apr_thread_cond_wait() call.


Thanks.
- INOUE Seiichiro <in...@ariel-networks.com>

Re: Win32 apr_thread_cond_wait() has a mutex problem?

Posted by Branko Čibej <br...@xbc.nu>.
INOUE Seiichiro wrote:

>apr_thread_cond_wait()/apr_thread_cond_timedwait() on Win32 seem to have a mutex problem.
>
There's a race condition there. Search the mail list archives -- I
posted a patch a couple of weeks ago. However, I haven't committed it
yet because there's still a race there. I'm slowly working on a correct
condition variable implementation for Windows.



-- 
Brane Čibej   <br...@xbc.nu>   http://www.xbc.nu/brane/