#include <boost/thread.hpp>
#include <boost/chrono.hpp>
#include <iostream>
#include <exception>

using namespace std;
void worker(int tid) {
	try {
		while (true) {
			boost::this_thread::interruption_point();
			boost::this_thread::sleep_for(boost::chrono::milliseconds(100));
		}
	} catch (...) {
		//cout << "Thread:" << tid << " interupted " << endl;
	}
}


int main() {
	boost::thread_group tg;
	int count;

	try { 
	while (true) {
		tg.create_thread(boost::bind(worker,count));
		//boost::this_thread::sleep_for(boost::chrono::milliseconds(10));
		count++;
	}
	} catch (exception &e) {
		//cout << "Exception:" << e.what() << endl;
		cout << "Max count = " << count << endl;
		
	}

	tg.interrupt_all();
	tg.join_all();

}
