[thread] Is a call to interrupt_all blocking?
Does a call to interrupt_all blocks the calling thread, waiting for all threads to be interrupted? Or is it supposed to return immediately and let the threads hit their interruption points later? I have a thread_group and I want to call interrupt_all to stop all threads in the group from 'within' one of the threads in that group. This would be possible only if interrupt_all in not blocking, otherwise I will need to somehow signal some other thread to do the interrupt_all on that group. SG
Sachin Garg
Does a call to interrupt_all blocks the calling thread, waiting for all threads to be interrupted? Or is it supposed to return immediately and let the threads hit their interruption points later?
interrupt_all is not blocking. However, there is currently a bug in interruption on pthreads which means threads can miss interruptions if they get a spurious condition variable wake at the wrong time. Since interruption causes spurious wakes for other threads waiting on the same cv this is particularly a problem for interrupt_all. 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
Anthony Williams
interrupt_all is not blocking. However, there is currently a bug in interruption on pthreads which means threads can miss interruptions if they get a spurious condition variable wake at the wrong time. Since interruption causes spurious wakes for other threads waiting on the same cv this is particularly a problem for interrupt_all.
Anthony, what is the schedule, if any, for getting a fix for the bug you refer to? The project I am currently working on, in development within a win32 environment, but soon to be ported to a VxWorks/PPC (using pthreads) environment does use interruption facilities. If this will be a problem for us, let's say not fixed up within the next 6 months, then I'll have to utilize alternate schemes. Geoff Shapiro FLIR Systems, Inc.
Geoff Shapiro wrote:
Anthony Williams
writes: interrupt_all is not blocking. However, there is currently a bug in interruption on pthreads which means threads can miss interruptions if they get a spurious condition variable wake at the wrong time. Since interruption causes spurious wakes for other threads waiting on the same cv this is particularly a problem for interrupt_all.
Anthony, what is the schedule, if any, for getting a fix for the bug you refer to? The project I am currently working on, in development within a win32 environment, but soon to be ported to a VxWorks/PPC (using pthreads) environment does use interruption facilities. If this will be a problem for us, let's say not fixed up within the next 6 months, then I'll have to utilize alternate schemes.
Geoff Shapiro FLIR Systems, Inc.
There was a discussion about this topic a few weeks ago, e.g.: http://lists.boost.org/boost-users/2009/12/54165.php If I got it right, a workaround is { boost::mutex::scoped_lock lock(mutex_); // lock the mutex of the cv threadGroup_.interrupt_all(); } // unlock the mutex HTH, Roland
Roland Bock
There was a discussion about this topic a few weeks ago, e.g.: http://lists.boost.org/boost-users/2009/12/54165.php
If I got it right, a workaround is
{ boost::mutex::scoped_lock lock(mutex_); // lock the mutex of the cv threadGroup_.interrupt_all(); } // unlock the mutex
Ahh, terrific. Thanks, Roland. That will work pending the proper fix within boost::thread itself. Geoff Shapiro FLIR Systems, Inc.
Geoff Shapiro
Anthony Williams
writes: interrupt_all is not blocking. However, there is currently a bug in interruption on pthreads which means threads can miss interruptions if they get a spurious condition variable wake at the wrong time. Since interruption causes spurious wakes for other threads waiting on the same cv this is particularly a problem for interrupt_all.
Anthony, what is the schedule, if any, for getting a fix for the bug you refer to? The project I am currently working on, in development within a win32 environment, but soon to be ported to a VxWorks/PPC (using pthreads) environment does use interruption facilities. If this will be a problem for us, let's say not fixed up within the next 6 months, then I'll have to utilize alternate schemes.
I have an idea on how to fix it; I just need to find the time to try it out. 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
Anthony Williams
I have an idea on how to fix it; I just need to find the time to try it out.
Hope you find that time sometime soon... :-), if not for 1.42 (unlikely), then for sure by 1.43... If you need verification on a VxWorks 6.8/PPC platform let me know - I can easily do that for you. Geoff Shapiro FLIR Systems, Inc.
On Tue, Jan 26, 2010 at 4:22 PM, Anthony Williams
Sachin Garg
writes: Does a call to interrupt_all blocks the calling thread, waiting for all threads to be interrupted? Or is it supposed to return immediately and let the threads hit their interruption points later?
interrupt_all is not blocking.
My blocking problem seems to be because I am calling interrupt_all when another thread is already waiting on a join_all for same thread_group. Similar to the issue described in the post below. I am using boost 1.39.0, is this fixed in current 1.41.0? http://lists.boost.org/boost-users/2009/10/53107.php
However, there is currently a bug in interruption on pthreads which means threads can miss interruptions if they get a spurious condition variable wake at the wrong time. Since interruption causes spurious wakes for other threads waiting on the same cv this is particularly a problem for interrupt_all.
I think I can live with this bug for a while :-) let me know if I am misunderstanding it. The condition variable bug *seems* to mean that in worst case a thread a may miss one interruption point and then get interrupted at its next interruption point (the interruption is not lost, just delayed) This will be ok in my application as missing an interruption is not fatal and it does not cause any deadlocks etc (the thread will surely reach its next interruption point soon and then get interrupted). Is the fix for this expected in 1.42.0? 1.42.0 release seems to be very close. Anyway, if my understanding of bug is correct, I can live with it for a while. Thanks for your help. SG
Sachin Garg
On Tue, Jan 26, 2010 at 4:22 PM, Anthony Williams
wrote: Sachin Garg
writes: Does a call to interrupt_all blocks the calling thread, waiting for all threads to be interrupted? Or is it supposed to return immediately and let the threads hit their interruption points later?
interrupt_all is not blocking.
My blocking problem seems to be because I am calling interrupt_all when another thread is already waiting on a join_all for same thread_group. Similar to the issue described in the post below. I am using boost 1.39.0, is this fixed in current 1.41.0?
Yes.
However, there is currently a bug in interruption on pthreads which means threads can miss interruptions if they get a spurious condition variable wake at the wrong time. Since interruption causes spurious wakes for other threads waiting on the same cv this is particularly a problem for interrupt_all.
I think I can live with this bug for a while :-) let me know if I am misunderstanding it.
The condition variable bug *seems* to mean that in worst case a thread a may miss one interruption point and then get interrupted at its next interruption point (the interruption is not lost, just delayed)
Yes, that's right. The problem is that the interrupted thread may miss the interruption, and thus remain waiting on the CV. If the CV is subsequently signalled or broadcast then the thread will wake and see the interruption.
Is the fix for this expected in 1.42.0? 1.42.0 release seems to be very close. Anyway, if my understanding of bug is correct, I can live with it for a while.
V1.42 is indeed very close. This bug was marked as a showstopper in trac. If anyone thinks it is a showstopper for them, reply to Marshall's post on the boost devel list to say so and I'll try and get the fix done for 1.42. Otherwise it will have to wait for 1.43. 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
participants (4)
-
Anthony Williams
-
Geoff Shapiro
-
Roland Bock
-
Sachin Garg