See the following code:
boost::thread_group threads;
boost::barrier barrier(10);
thing pThing;
for( size_t i = 0; i < 10; ++i )
{
threads.create_thread(
[&barrier, &pThing]()
{
while( true )
{
// do some stuff with pThing
if( barrier.wait() ) // let all threads catch up before resettings, and only 1 thread resets
pThing.Reset();
barrier.wait(); // let all threads wait until the reset is completed
}
});
}
threads.join_all();
Questions:
- Do I need a way to break the while(true) for the threads to exit correctly?
- Will
join_all()complete since all the threads are infinite looping? - what happens when a thread finishes its work, does it die?
- Is
barrier.wait()an interruption point? - Do interruption points just yield the thread?
- What happens when the thread_group dies; Do I even need to
join_all()if the thread group it going to die right afterwards anyway?
interrupt_all()call first.interrupt()call sets this flag on a thread and, additionally, makes the thread stop waiting if that’s what it’s doing currently.join_all()and only then destroy the thread group object.