Boost logo

Boost Users :

Subject: [Boost-users] [thread] terminating a thread when a program exits
From: Sean Farrow (sean.farrow_at_[hidden])
Date: 2011-07-09 22:15:48


Hi:
I've got a situation whereby, I've got a number of boost::thread objects being created by classes in my program and run for the duration of the program. What I need to do is when the exit menu item is activated, close down all threads.
I was going to use a condition, and have the threads continue until the condition is signalled, and then use notify_all when the exit menu item is activated.
Given that I want this condition to be multi-read/exclusive write, what mutex is the best option?
Also will I need to use a mutex in the threads I need to terminate.
I see the code of the threads being something like:
While (Terminate !=false)
{
//perform actions.
};
Normally in this situation I'd use a windows event and the WaitForSingle/multipleObject functions, but as this has to be cross platform I carn't do this.
Any help with this appreciated.
Cheers
Sean.



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