EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Re: epicsEvent (posix implementation) bug ?
From: Till Straumann <[email protected]>
To: Andrew Johnson <[email protected]>
Cc: [email protected]
Date: Mon, 31 Jan 2011 11:34:25 -0600
On 01/31/2011 10:40 AM, Andrew Johnson wrote:
On Friday 28 January 2011 19:57:02 Till Straumann wrote:
If multiple threads block on the same event then the current
implementation (posix) may spuriously wake up more than
one thread as a result of epicsEventSignal().

This is because the underlying pthread_cond_signal()/pthread_cond_wait()
explicitly have these same semantics.

IMO it would be a good idea to change epicsEventWait and
epicsEventWaitWithTimeout so that they handle this possible
case (and yield the same semantics as the RTEMS and vxWorks
variants).

Could someone add a failing test to libCom/test/epicsEventTest.cpp to try and
demonstrate this issue please.

This is hard. If anything, it is a hard to be reproduced type of thing,
i.e., a rare race condition which the pthreads API explicitly permits
(but does of course not demand).

http://pubs.opengroup.org/onlinepubs/007908799/xsh/pthread_cond_signal.html

"The pthread_cond_signal() call unblocks **at*least*one** of the threads
that are blocked on the specified condition variable..."

(emphasis by me).

Replacing 'if' by 'while' removes that possibility (i.e., that epicsEventSignal() releases more than one thread).

I don't know why that comment was added (it's not part of my patch)
but my guess is that the author believed that the caller of epicsEventWait() should be prepared for a situation where an event
is spuriously sent. IMO this is not a good assumption since the
implementation of epicsEventWait() should not make any assumptions
about the nature of the application that uses an epicsEvent.

Especially given the fact that the RTEMS and vxWorks implementations
IIRC guarantee that epicsEventSignal() releases exactly one thread
it would IMHO be desirable for the posix implementation to provide
the same semantics.

T.

 I don't have a proper understanding of what
the issue is yet, but I don't know the pthreads API very well — I'm not
denying that an issue exists, just trying to understand it.  I'm also
wondering why the line above the if() that you suggest converting into a
while() might contain the comment "no need for while since caller must be
prepared for no work."

- Andrew


Replies:
Re: epicsEvent (posix implementation) bug ? Andrew Johnson
References:
epicsEvent (posix implementation) bug ? Till Straumann
Re: epicsEvent (posix implementation) bug ? Andrew Johnson

Navigate by Date:
Prev: Re: epicsEvent (posix implementation) bug ? Eric Norum
Next: Re: epicsEvent (posix implementation) bug ? Till Straumann
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Re: epicsEvent (posix implementation) bug ? Andrew Johnson
Next: Re: epicsEvent (posix implementation) bug ? Andrew Johnson
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 18 Nov 2013 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·