// stop_while_thread.cpp :
//
#include "stdafx.h"
#include <boost/thread.hpp>
#include <iostream>
using namespace std;
void thread_proc()
{
try
{
while(true)
{
boost::this_thread::interruption_point();
cout << "Processing..." << endl;
boost::this_thread::sleep(boost::posix_time::seconds(1));
}
}
catch(...)
{
cout << "Catch interruption." << endl;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
cout << "max concurrency thread cnt = " << boost::thread::hardware_concurrency() << endl;
boost::thread t1(thread_proc);
string str;
while(str != "quit")
{
cin >> str;
if(str == "break")
{
cout << "kill thread." << endl;
t1.interrupt();
}
}
cout << "main exit.";
system("pause");
return 0;
}