problems with pthread_cond_broadcast

Scott Lamb slamb at slamb.org
Thu Apr 15 07:56:26 UTC 2004


On Apr 15, 2004, at 2:48 AM, Thorsten Kukuk wrote:

> On Thu, Apr 15, Scott Lamb wrote:
>
>> I think there is a problem in your test case. And I _sort_of_ see it.
>> Imagine this sequence of events:
>>
>> Thread 1            Thread 2
>> ----------------------------------------
>> rw_lock_write:      rw_lock_write:
>>   mutex_lock
>>   n_readers = -1
>>   mutex_unlock
>>                       mutex_lock
>>                       n_readers != 0
>> rw_unlock_write:
>>   mutex_lock
>
> At this place, two threads would have mutex_lock. That should
> not happen and I don't see how it can happen.

Indeed. Sorry, I blame a cut'n'paste accident. Trying to come up with 
the correct sequence. I thought I had it at one point, anyway. Grr.

What I'm looking for, though, is a situation where thread 1's 
pthread_cond_broadcast is after thread 2's n_readers != 0 comparison 
yet before thread 2's pthread_cond_wait. That can't happen when the 
mutex is still held for the broadcast. I had 3 threads involved before, 
maybe that is necessary...

Scott





More information about the Phil-list mailing list