[390] in Pthreads mailing list archive
How to block on a file descriptor OR condition variable?
daemon@ATHENA.MIT.EDU (drh@tobit.vnet.net)
Thu Aug 22 13:49:41 1996
From: drh@tobit.vnet.net
Date: Thu, 22 Aug 96 13:15 EDT
To: pthreads@MIT.EDU
I need a thread to block waiting on any of three events:
1) Data becomes available on a file descriptor.
2) Another thread signals a condition variable.
3) A timer expires.
I can do 1 and 3 with a select() call, or I can do 2 and 3 using
pthread_cond_timedwait(). But how can I do all three?
I had originally hoped to use select() and then have other threads
send the blocked thread a signal (SIGUSR1) to wake it from its
select() as needed. On many UNIX systems, any signal received will
cause select() to return early. But, unfortunately, this is not
the case to Provenzano's pthreads. The signal handler is still
called, but not until after the select() call returns as it normally
would.
As a temporary work-around, I'm polling between select() and
pthread_cond_timedwait(). I figure I can flip back and forth between
these two every 50 milliseconds are so without imposing too much
extra load on the system, and without introducing too much delay
in the receipt of events. But this is a compromise. I'd prefer
to do it ``right''.
Any suggestions?
E-Mail responses to drh@tobit.vnet.net are appreciated.
Peace.
-----------------
D. Richard Hipp drh@tobit.vnet.net