Boost logo

Boost Users :

Subject: [Boost-users] Is boost::this_thread::sleep_for interruption point?
From: Serg Gulko (s.gulko_at_[hidden])
Date: 2012-07-23 20:57:52


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-interruption-point-tp4633485.html
Sent from the Boost - Users mailing list archive at Nabble.com.

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