/*Racing example*/

#include <iostream>
#include <boost/thread.hpp>
//#include <boost/atomic.hpp>
#include <boost/thread/mutex.hpp>

using namespace boost;
boost::mutex mtx;
//int counter=0;
//there is atomic on std also

atomic<int> counter(0);
void worker() {
	for(int i=0; i<100000; i++){
		mtx.lock();
		++counter;
		mtx.unlock();
	}
}

int main() {
	thread *t1=new thread(worker);
	thread t2(worker);
	thread *t3 = new thread(worker);
	thread *t4 = new thread(worker);

	t1->join();
	t2.join();
	t3->join();
	t4->join();
	std::cout<<"Final counter = " << counter << std::endl;
	return 0;
}	
