Is boost::this_thread::sleep_for interruption point?
Hello! According to documentation(v 1.50.0) call boost::this_thread::sleep_for can be interrupted. For some reason this functionality not works for me. Here is code sample: //Simple thread function void Test::worker(int delay) { try { boost::this_thread::sleep_for(boost::chrono::milliseconds(delay)); cout << "Doing some work" << endl; } catch (boost::thread_interrupted const& e) { cout << "INTERRUPTED" << endl; } } //Far in the code boost::thread workerThread(boost::bind(&Test::worker, this, 1200)); boost::this_thread::sleep(boost::posix_time::milliseconds(30)); workerThread.interrupt(); boost::this_thread::sleep(boost::posix_time::milliseconds(1500)); I always getting 'Doing some work'... -- View this message in context: http://boost.2283326.n4.nabble.com/Is-boost-this-thread-sleep-for-interrupti... Sent from the Boost - Users mailing list archive at Nabble.com.
On Mon, Jul 23, 2012 at 5:57 PM, Serg Gulko
For some reason this functionality not works for me.
Change this function:
//Simple thread function void Test::worker(int delay) { try { boost::this_thread::sleep_for(boost::chrono::milliseconds(delay)); cout << "Doing some work" << endl; } catch (boost::thread_interrupted const& e) { cout << "INTERRUPTED" << endl; } }
To this: void Test::worker(int delay) { try { while (true) { boost::this_thread::sleep_for(boost::chrono::milliseconds(delay)); cout << "Doing some work" << endl; } } catch (boost::thread_interrupted const& e) { cout << "INTERRUPTED" << endl; } }
In my code I using boost::this_thread::sleep_for(boost::chrono::milliseconds(duration)) and can't interrupt it. -- View this message in context: http://boost.2283326.n4.nabble.com/Is-boost-this-thread-sleep-for-interrupti... Sent from the Boost - Users mailing list archive at Nabble.com.
Le 24/07/12 02:57, Serg Gulko a écrit :
Hello!
According to documentation(v 1.50.0) call boost::this_thread::sleep_for can be interrupted. For some reason this functionality not works for me. Here is code sample:
//Simple thread function void Test::worker(int delay) { try { boost::this_thread::sleep_for(boost::chrono::milliseconds(delay)); cout << "Doing some work" << endl; } catch (boost::thread_interrupted const& e) { cout << "INTERRUPTED" << endl; } }
//Far in the code
boost::thread workerThread(boost::bind(&Test::worker, this, 1200)); boost::this_thread::sleep(boost::posix_time::milliseconds(30)); workerThread.interrupt(); boost::this_thread::sleep(boost::posix_time::milliseconds(1500));
I always getting 'Doing some work'...
Hi, No you should be right, I remember that there were a ticket related that is closed now https://svn.boost.org/trac/boost/ticket/7238. Best, Vicente
participants (3)
-
Chris Stankevitz
-
Serg Gulko
-
Vicente J. Botet Escriba