staticanalysis / data-race-test

Automatically exported from code.google.com/p/data-race-test
0 stars 0 forks source link

[v2] false positive on DISABLED_HappensBeforeArcBetweenChildThreads #91

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
  MemLoc l;                                                                                                                                                                                         
  ScopedThread t1;                                                                                                                                                                                  
  t1.Write1(l);                                                                                                                                                                                     
  ScopedThread t2;                                                                                                                                                                                  
  t2.Write1(l);             

make && ./tests/tsan_test --gtest_also_run_disabled_tests 
--gtest_filter=*DISABLED_HappensBeforeArcBetweenChildThreads

[ RUN      ] ThreadSanitizer.DISABLED_HappensBeforeArcBetweenChildThreads
==================
WARNING: ThreadSanitizer: data race
  Write of size 1 at 0x7f3db4082718 by thread 3:
    #0 0x7f3db3e0dcca: ScopedThread::Impl::HandleEvent(Event*) tsan_test_util_linux.cc:253
  Previous Write of size 1 at 0x7f3db4082718 by thread 2:
    #0 0x7f3db3e0dcca: ScopedThread::Impl::HandleEvent(Event*) tsan_test_util_linux.cc:253

The reason we report this false positive is that we don't create a h-b arc 
between thread_create (in parent) and thread_start (in child). 

I tried adding the following patch but it did not help. What did I miss?

--- tsan/tsan_interceptors.cc   (revision 3998)
+++ tsan/tsan_interceptors.cc   (working copy)
@@ -259,6 +259,7 @@
   void* (*callback)(void *arg);
   void *param;
   atomic_uintptr_t tid;
+  uptr fake_sync_object;
 };

 static void *tsan_thread_start(void *arg) {
@@ -274,6 +275,7 @@
     pthread_yield();
   atomic_store(&p->tid, 0, memory_order_release);
   ThreadStart(cur_thread(), tid);
+  Acquire(cur_thread(), 0, p->fake_sync_object);
   void *res = callback(param);
   return res;
 }
@@ -287,7 +289,9 @@
   ThreadParam p;
   p.callback = callback;
   p.param = param;
+  p.fake_sync_object = (uptr)callback;  // FIXME: chose some better fake addr.
   atomic_store(&p.tid, 0, memory_order_relaxed);
+  Release(cur_thread(), pc, p.fake_sync_object);
   int res = REAL(pthread_create)(th, attr, tsan_thread_start, &p);
   if (res == 0) {
     int tid = ThreadCreate(cur_thread(), pc, *(uptr*)th, detached);

Original issue reported on code.google.com by konstant...@gmail.com on 19 Mar 2012 at 9:22

GoogleCodeExporter commented 9 years ago
DISABLED_HappensBeforeArcBetweenChildThreads

It is a real race.

--gtest_filter=*DISABLED_HappensBeforeArcBetweenChildThreads

tsan_test_util_linux.cc:253

tsan_test_util_linux.cc:253

arc between thread_create (in parent) and thread_start (in child).

addr.

Original comment by dvyu...@google.com on 20 Mar 2012 at 4:43

GoogleCodeExporter commented 9 years ago
oops. facepalm 

Original comment by konstant...@gmail.com on 20 Mar 2012 at 4:47