Using Windows Slim Reader Writer Locks gives false positives for data race?

Using Windows Slim Reader Writer Locks gives false positives for data race?

I have code which does the following:

ThreadA():

AcquireSRWLockExclusive(lock);

SharedVar = someVal;

ReleaseSRWLockExclusive(lock);

...

ThreadB()

AcquireSRWLockShared(lock);

var = SharedVar;

ReleaseSRWLockShared(lock);

When I run the Intel Inspector to Locate Deadlocks and Data Races it says that there is read/write data race in accessing the presimably locked SharedVar. Does the Intel Inspector properly work with slim reader / writer locks or should I just discard the issue as a false positive?

5 帖子 / 0 全新
最新文章
如需更全面地了解编译器优化,请参阅优化注意事项

>>...When I run the Intel Inspector to Locate Deadlocks and Data Races it says that there is read/write data race...

It looks right because both threads are not waiting until the shared resource is avalable.

>>...should I just discard the issue as a false positive?

Could you try the test case with TryAcquireSRWLockShared and TryAcquireSRWLockExclusive functions?

Hi Stefan,

did you first initialize slim reader/writer lock with InitializeSRWLock() function?

>>>>...When I run the Intel Inspector to Locate Deadlocks and Data Races it says that there is read/write data race...
>>
>>did you first initialize slim reader/writer lock with InitializeSRWLock() function?

Intel Inspector XE would not detect the data race if something would be wrong with initialization the SRW lock.

>>...should I just discard the issue as a false positive?

Since ThreadA is a Writer thread ( changes value of the shared variable ) and ThreadB is a Reader thread ( reads value of the shared variable ) then a message about the data race could be considered as a warning. By design of SRW multiple threads ( readers! ) should be able to access some resource.

Yes. I did initialize the lock. Also i have a test which will detect if a reader thread accesses not fully written data. The test has been running for a day with no issues. 

I've also tried the sample from "Synchronization Primitives New To Windows Vista" (http://msdn.microsoft.com/en-us/magazine/cc163405.aspx). The Intel Inspector detects a race condition in that code too (in updateValue() and getValue()).

发表评论

登录添加评论。还不是成员?立即加入