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 <[EMAIL PROTECTED]>

Reply via email to