[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: problems with pthread_cond_broadcast



On Thu, Apr 15, Sebastien Decugis wrote:

> Hi,
> 
> I think this problem is the same as:
> http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=115349
> and
> http://bugme.osdl.org/show_bug.cgi?id=2364
> 
> Moreover, POSIX says:
> "The pthread_cond_broadcast() or pthread_cond_signal() functions may be
> called by a thread whether or not it currently owns the mutex that
> threads calling pthread_cond_wait() or pthread_cond_timedwait() have
> associated with the condition variable during their waits"
> 
> So there is a bug in either NPTL or kernel futexes (FUTEX_REQUEUE ?), as
> your use of pthread_cond_broadcast() after pthread_mutex_unlock() is
> legal.

Yes, it is legal to call pthread_cond_broadcast() after 
pthread_mutex_unlock(). But POSIX above says "have
associated with the condition variable during their waits".

This means for me, that they called already pthread_cond_wait() and
not that they are allowed to call pthread_cond_wait() at the same
time as pthread_cond_broadcast() with the same condition variable.

I cannot find anything in POSIX which says, that it is allowed that
pthread_cond_wait() and pthread_cond_broadcast() access the same
variable at the same time, for me it always sounds like POSIX expects
that other threads are already waiting.

So are both functions allowed to access the same variable at the
same time or not? I would expect that they are not allowed to do
so and cannot find something different in POSIX.

  Thorsten

> Le jeu 15/04/2004 à 07:50, Thorsten Kukuk a écrit :
> > Hi,
> > 
> > I have a problem with pthread_cond_wait/pthread_cond_broadcast
> > waiting sometimes forever on a fast SMP machine. Attached is a
> > simple test case.
> > 
> > If I use the order
> >   pthread_mutex_unlock (&lock);
> >   pthread_cond_broadcast (&pcond);
> > 
> > with NPTL, the program will hang after a short time running with
> > current glibc + NPTL + kernel 2.6.x on all architectures I tested.
> > 
> > If I revert the order to 
> >   pthread_cond_broadcast (&pcond);
> >   pthread_mutex_unlock (&lock);
> > 
> > it works fine.
> > 
> > Is this a problem of the test case (since pthread_cond_broadcast and
> > pthread_cond_wait will access pcond at the same time in different
> > threads) or is this a glibc/NPTL/kernel problem?
> > 
> >  Thanks for any hint,
> > 
> >     Thorsten
> -- 
> Sébastien DECUGIS
> Bull S.A.

-- 
Thorsten Kukuk       http://www.suse.de/~kukuk/        kukuk suse de
SuSE Linux AG        Maxfeldstr. 5                 D-90409 Nuernberg
--------------------------------------------------------------------    
Key fingerprint = A368 676B 5E1B 3E46 CFCE  2D97 F8FD 4E23 56C6 FB4B



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]