/*Racing Example*/
#include <iostream>
#include <boost/thread.hpp>
//#include <boost/atomic.hpp>
#include <boost/thread/mutex.hpp>
using namespace boost;
using namespace std;
int counter=0;
boost::mutex mtx;
//boost::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();
        cout << "Final counter=" << counter << endl;
        return 0;

}

