- #include <boost/thread.hpp>
- #include <boost/thread/mutex.hpp>
- #include <iostream>
- boost::mutex io_mutex;
- using namespace std;
- void wait(int seconds)
- {
- boost::this_thread::sleep(boost::posix_time::seconds(seconds));
- }
- void interruptedThread()
- {
- try
- {
- for (int i = 0; i < 5; i++)
- {
- wait(1);
- cout << i << endl;
- }
- }
- catch (boost::thread_interrupted&)
- {
- cout << "thread_interrupted exception happened";
- }
- }
- void testInteruptedThread()
- {
- boost::thread t(interruptedThread);
- wait(3);
- t.interrupt();
- t.join();
- }
- int main(int argc, char* argv[])
- {
- testInteruptedThread();
- return 0;
- }
相关文章: