//racing example

#include <iostream>
#include <boost/chrono.hpp>
#include <boost/thread.hpp>
////#include <boost/atomic.hpp>
#include <boost/thread/mutex.hpp>
using namespace std;
using namespace boost;

int counter=0;
boost::mutex mtx;
////boost::atomic<int> counter(0);

void worker(){
	for (int i=0; i<10000; 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();
	t3->join();

	cout <<"final counter " <<counter <<endl;

return 0;
}
