|
Boost Users : |
From: dmoore99atwork (dmoore_at_[hidden])
Date: 2002-04-09 20:53:26
--- In Boost-Users_at_y..., dick.bridges_at_t... wrote:
> Threads in a thread_group - derived pool are waiting on a condition.
> Condition gets notify_one(). How do I get id/pointer for the
thread that
> was released? I've got a feeling I'm gonna be *REAL* embarrassed
when I
> find out, but I can't figure it out.
>
> Thanks for any help.
Dick,
In general, condition variables (both the Boost.Threads version and
the POSIX version) don't tell the "notifier" which thread woke up.
That's not necessarily a problem, though. A thread pool usually
implies a set of threads that are equivalent in some way, even
running the same thread function.
Referring to the example at:
http://www.boost.org/libs/thread/doc/condition.html#Example,
Take a look the the receive() function.
while (buffered == 0)
buffer_not_empty.wait(lk);
You might have three threads which reach this point when buffered==0
(meaning the buffer is empty). When a new sender in a fourth thread
adds something to the buffer and calls notify_one(), exactly one of
the three threads waiting on the condition will wake up and do some
work. You won't care which thread wakes up, because any one of them
will be prepared to do the necessary work.
If this doesn't get you unstuck, please post more details, in
particular why you feel it is important to know which thread "woke up"
Regards,
Dave
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net