This is the mail archive of the glibc-linux@ricardo.ecn.wfu.edu mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: pthreads and poll





On  Thu,     20    Jan   2000    kaz@FootPrints.net wrote:
>
> On Thu, 20 Jan 2000 kd@flaga.is wrote:
>
> > Hi,
> >
> > According to the man page for poll() it says it should return EINTR if
a
> > signal occurred before any of the requested poll events happened.
> > Now I have the following threads,
> >
> > 1) threadA is sleeping in poll
> > 2) threadB signals a condition variable
> >
> > As I understand, pthreads on linux use unix signals to signal threads
> > although abstracted by pthreads.
> > So my questions:
> >
> > 1) Is it a bug that threadA (the one sleeping on poll) is not
"interrupted"
> > when a pthreads signal occurred?
> > 2) If not, how can I make sure that threadA is woken up (interrupted)
when
> > a pthread signal occurred?
>
> If I am to understand correctly, you expect the pthread_cond_signal
> operation to unblock threadA even though threadA is  not waiting on that
> condition variable.
>
> That is simply unreasonable. The signalling of a condition should not
affect
> threads that are not waiting on that condition.
>
> The signals used by LinuxThreads internally are directed at specific
threads.
> For example if you do pthread_cond_broadcast() then a resume signal is
sent
> to each thread that was waiting on the given condition variable, not to
> other threads.
>
> If you want to shut down the thread that is waiting in poll, what you can
do is
> pthread_cancel() it.  Have it call pthread_testcancel() whenever it wakes
up,
> since poll is not a cancellation point. LinuxThreads will do the job of
waking
> up the poll, but poll does not have a built in test for cancellation.
>
> You can also use pthread_kill() to send specific signals to specific
threads.

Hmm, o.k. maybe I didnīt formulate my question well enough. Let's say that
I have a condition variable and
a condition that I want to wait for to become true. The condition is

 (cond ==1) || (dataAvailable from /dev/mydev)

The first part of the condition is easy to evaluate but the second is more
difficult to evaluate in this context because
I will always go to sleep on the poll() call, as well as falling asleep on
pthread_cond_wait().

So my problem is basically, I can be sleeping in the wrong call (poll() or
pthread_cond_wait()) when the "other" event happens.

Am I thinking about this completely in the wrong way?

K.D.

P.S. Maybe the question can be stated as "How can I combine poll() and
pthread_cond_wait() into a single entity?"


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]