#include <iostream>
#include <boost/thread.hpp>
#include <boost/thread/barrier.hpp>
#include <boost/chrono.hpp>
#include <cstdlib>
#include <ctime>

using namespace std;

void worker(int id, boost::barrier &sync_point) {
	cout << " thread: " << id << " entering work" << endl;
	boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
	sync_point.wait();
	cout << "thread: " << id << " leaving barrier" << endl;
}



int main() {
	srand(time(0));
	int num_threads = rand()%6+3;
	cout<<" Creating: " << num_threads << endl;
	boost::barrier sync_point(num_threads);

	boost::thread_group tg;
	for (int i = 0;i<num_threads;i++) {
		tg.create_thread(boost::bind(worker,i,boost::ref(sync_point)));
	}
	tg.join_all();





	return 0;
}
