tsan: fix a potential hang
authorDmitry Vyukov <dvyukov@google.com>
Tue, 8 Jul 2014 13:36:59 +0000 (13:36 +0000)
committerDmitry Vyukov <dvyukov@google.com>
Tue, 8 Jul 2014 13:36:59 +0000 (13:36 +0000)
idx0 is not updated in the branch,
so if we take that branch idx0 will stay updated forever

llvm-svn: 212532

compiler-rt/lib/tsan/rtl/tsan_sync.cc

index 3952b2f..3462b04 100644 (file)
@@ -133,7 +133,7 @@ SyncVar* MetaMap::GetAndLock(ThreadState *thr, uptr pc,
   u32 myidx = 0;
   SyncVar *mys = 0;
   for (;;) {
-    u32 idx = *meta;
+    u32 idx = idx0;
     for (;;) {
       if (idx == 0)
         break;
@@ -156,8 +156,10 @@ SyncVar* MetaMap::GetAndLock(ThreadState *thr, uptr pc,
     }
     if (!create)
       return 0;
-    if (*meta != idx0)
+    if (*meta != idx0) {
+      idx0 = *meta;
       continue;
+    }
 
     if (myidx == 0) {
       const u64 uid = atomic_fetch_add(&uid_gen_, 1, memory_order_relaxed);