|
Boost Users : |
From: Maximilian Wilson (wilson.max_at_[hidden])
Date: 2007-11-16 11:25:12
On Nov 16, 2007 7:58 AM, Andrey Tcherepanov <moyt63c02_at_[hidden]>
wrote:
> Hello boosters,
>
> Let's say I have a 2 condition variables, and 2 threads that wait on them.
> I would like to collapse these 2 threads into 1 by making thread wait on
> *either* of these conditions to lock their mutexes (it is not the same
> mutex). Is it possible to do, or I better change the logic under the hood?
>
>
It can be done, although it might be better not to. Use a counting semaphore
in the place of the two mutexes, and when a producer signals the semaphore
he should first set a global flag variable to indicate that he's done; when
the consumer acquires the semaphore he will check both global variables to
see which producer signalled him (or possibly both).
-Max
-- "The presentation or 'gift' of the Holy Ghost simply confers upon a man the right to receive at any time, when he is worthy of it and desires it, the power and light of truth of the Holy Ghost, although he may often be left to his own spirit and judgment." --Joseph F. Smith (manual, p. 69) Be pretty if you are, Be witty if you can, But be cheerful if it kills you.
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