[compiler-rt] r200922 - [TSan] Don't flush all file streams on program shutdown to avoid deadlocks on file stream locks.

Alexander Potapenko glider at google.com
Thu Feb 6 05:37:14 PST 2014


Author: glider
Date: Thu Feb  6 07:37:14 2014
New Revision: 200922

URL: http://llvm.org/viewvc/llvm-project?rev=200922&view=rev
Log:
[TSan] Don't flush all file streams on program shutdown to avoid deadlocks on file stream locks.
This should fix https://code.google.com/p/thread-sanitizer/issues/detail?id=47.

Modified:
    compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc?rev=200922&r1=200921&r2=200922&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Thu Feb  6 07:37:14 2014
@@ -62,6 +62,7 @@ extern "C" void *__libc_calloc(uptr size
 extern "C" void *__libc_realloc(void *ptr, uptr size);
 extern "C" void __libc_free(void *ptr);
 extern "C" int mallopt(int param, int value);
+extern void *stdout, *stderr;
 const int PTHREAD_MUTEX_RECURSIVE = 1;
 const int PTHREAD_MUTEX_RECURSIVE_NP = 1;
 const int EINVAL = 22;
@@ -2103,7 +2104,11 @@ static void finalize(void *arg) {
   uptr pc = 0;
   atexit_ctx->exit(thr, pc);
   int status = Finalize(thr);
-  REAL(fflush)(0);
+  // Make sure the output is not lost.
+  // Flushing all the streams here may freeze the process if a child thread is
+  // performing file stream operations at the same time.
+  REAL(fflush)(stdout);
+  REAL(fflush)(stderr);
   if (status)
     REAL(_exit)(status);
 }





More information about the llvm-commits mailing list