[PATCH] D33325: [sanitizer] Avoid possible deadlock in child process after fork

Dmitry Vyukov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 24 01:19:32 PDT 2017


dvyukov added inline comments.


================
Comment at: lib/tsan/rtl/tsan_rtl.cc:460
+  allocator()->ForceLock();
+  ctx->metamap.Lock();
+  StackDepotLockAll();
----------------
Now looking at this more closely and paging in some context.
This change is not necessary for tsan. To make it work we need to lock whole lot of mutexes. Memory allocator is less of a problem, when plain memory accesses can cause deadlock. We would need to lock trace mutexes of all threads, all sync objects, deadlock detector, internal allocator, annotations mutex, atexit mutex, global proc mutex and probably some more. Moreover we need to lock then in the proper order. For example, this change will cause deadlocks in otherwise working programs because allocator mutex needs to be locked after report mutex (see CanLockTab in tsan_mutex.cc for some ordering constraints).
Because of that tsan uses a different mechanism to systematically prevent deadlocks (grep for after_multithreaded_fork). So if the test works under tsan, let's leave tsan alone.


Repository:
  rL LLVM

https://reviews.llvm.org/D33325





More information about the llvm-commits mailing list