私は、私は簡単なプログラム作っ (http://code.google.com/p/data-race-test/wiki/ThreadSanitizer#Using_ThreadSanitizer)消毒剤のスレッドを実行してみると思った:違反へのアクセスは、ミューテックス(などのコメントと同期しているのでスレッドサニタイザーは使用できますか?
#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();
}
を私の知る限りプログラムはOKですが、そのプログラムがレースであってもなくて言います無料)。 しかし、tsanは文句を言って警告を出します: http://www.filedropper.com/output 私はツールを間違って使っていますか、それとも本当に良いのですか? 重要な場合はVS11 Betaを使用しています。
同期がなくてもプログラムは正しいでしょう... –
私はそう思っています。最初に参加すれば十分です。私は確信したかっただけです。 Ofcの2回目の参加が必要です。 – NoSenseEtAl
両方のジョインが必要ですが、それを書いた方法では同時性はありません。 –