I know about join and detach anyway thank you for advice.
Working version:
for(;;){
auto c = signal.connect([]()
{
ThreadHandle->interrupt();
//code for handling event1
});
try
{
//code for timeout
}
catch (boost::thread_interrupted&)
{
//thread interrupted by signal listener
boost::this_thread::sleep_for(boost::chrono::milliseconds(1000));
}}
when signal is 'catched' I interrupt main flow (timeout) and do stuff which
should be done if event occurs.
2015-03-23 12:24 GMT+01:00 Ben Pope
On Monday, March 23, 2015 07:08 PM, Norbert Wenzel wrote:
On 03/23/2015 11:59 AM, Ben Pope wrote:
On Monday, March 23, 2015 04:55 PM, Fu ji wrote:
int main() { boost::thread t1(SendSignal);
for (;;) { std::cout << "."; boost::this_thread::sleep_for(boost::chrono::milliseconds( 100)); }
auto c = signal.connect([]() //...
At this point the thread detaches and the process exits: http://www.boost.org/doc/libs/1_57_0/doc/html/thread/thread_ management.html#thread.thread_management.thread.destructor
You need to call t1.join() before exiting this scope.
That's true but the end of main() will never be reached (and also the signal will never be connected) since the for(;;)-loop will print dots and sleep forever before actually doing any work.
D'oh! I saw the less obvious problem first and went with it.
Does anybody program with explicit threads any more? :P
Ben
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/ mailman/listinfo.cgi/boost