apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From INOUE Seiichiro <in...@ariel-networks.com>
Subject Win32 apr_thread_cond_wait() has a mutex problem?
Date Thu, 10 Jul 2003 16:06:03 GMT
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 <inoue@ariel-networks.com>

Mime
View raw message