I thought of trying out thread sanitizer ( http://code.google.com/p/data-race-test/wiki/ThreadSanitizer#Using_ThreadSanitizer ) so I made a simple program:
#include <thread>
#include <atomic>
#include <vector>
#include <iostream>
#include <algorithm>
#include <mutex>
using namespace std;
int violated=0;
mutex mtx;
void violator()
{
lock_guard<mutex> lg(mtx);
violated++;
}
int main()
{
thread t1(violator);
t1.join();
thread t2(violator);
t2.join();
}
AFAIK program is OK since access to violated is synced with mutex(and like comments say even without that program is race free). But tsan complains and gives a bunch of warnings: http://www.filedropper.com/output So am I using the tool wrong, or is it not really good ? If important I'm using VS11 Beta.