// Racing example
#include <iostream>
#include <boost/thread.hpp>
#include <boost/atomic.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<1000000;++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();

	cout << "Final counter=" <<counter << endl;
}
