
On 26/07/10 14:55, Gaetano Mendola wrote:
On 07/26/2010 11:25 AM, Anthony Williams wrote:
I have thought about this problem lots, and decided that you cannot safely interrupt a condition variable wait on POSIX unless you have a mutex tied directly to each condition variable (as with condition_variable_any). I'm therefore not sure how to approach this --- either every boost::condition_variable has an extra pthread_mutex_t inside it, or interruption is limited to waits on boost::condition_variable_any.
I have to look in detail the boost::thread implementation to help you here.
Of course.
Is pthread_cancel() still a no go to be used in threads::interrupt implementation?
pthread_cancel is no-go because it has different semantics and cannot be translated into an exception.
Another source of hang with notify_all (and then with interrupt), is the following usage pattern:
1. Thread A: acquires a lock on mutex Ma 2. Thread A: does a wait on the condition C: C.wait(Ma) 3. Thread B: acquires a lock on mutex Mb 4. Thread B: does a wait on the condition C: C.wait(Mb)
Undefined behaviour --- all concurrent calls to condition_variable::wait must use the same mutex. You can use different mutexes with condition_variable_any, and you can use different mutexes for separate waits, but not for concurrent ones. Anthony -- Author of C++ Concurrency in Action http://www.stdthread.co.uk/book/ just::thread C++0x thread library http://www.stdthread.co.uk Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976