bug-commoncpp
[Top][All Lists]
Advanced

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

Re: [ Patch #623 ] ost::Conditional is broken with posix threads


From: Federico Montesino Pouzols
Subject: Re: [ Patch #623 ] ost::Conditional is broken with posix threads
Date: Fri, 1 Nov 2002 23:08:46 +0100
User-agent: Mutt/1.4i

        Hi, I think this patch needs to be commented on this
list. This patch does the lock/unlock of the mutex attached to the
condition variable inside the Conditional class. However, I think the
Conditional class is designed so that the user of the class is
responsible for calling enterMutex and leaveMutex as needed.

        In fact, if you call enterMutex like this patch proposes, the
user of Conditional would not be able to check for any condition
between enterMutex and pthread_cond_wait. Also, you would need to
incorporate the enter/leaveMutex around the signal/broadcast calls.

        Perhaps, a note should be added to the documentation of
Conditional stating that its user is responsible for calling
enterMutex and leaveMutex to avoid race conditions.

        Anders Blomgren wrote:

> ost::Conditional is totally broken on most systems with posix
> threads as it doesnt lock it's mutex before doing
> pthread_cond_wait().
>
>This patch is against 1.0.5
>
>--- commoncpp2-1.0.5/src/mutex.cpp      Thu May  9 01:18:30 2002
>+++ commoncpp2-1.0.5q/src/mutex.cpp     Fri Nov  1 05:51:38 2002
>@@ -148,11 +148,15 @@
>
>        if(!timeout)
>        {
>+               enterMutex();
>                pthread_cond_wait(&_cond, &_mutex);
>+               leaveMutex();
>                return;
>        }
>        getTimeout(&ts, timeout);
>+       enterMutex();
>        pthread_cond_timedwait(&_cond, &_mutex, &ts);
>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]