[PATCH] D18496: [tsan] Fix a crash when exiting the main thread (e.g. dispatch_main)

Kuba Brecka via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 27 07:42:08 PDT 2016

kubabrecka added inline comments.

Comment at: test/tsan/Darwin/dispatch_main.mm:28
@@ +27,3 @@
+      sleep(3);
+      exit(0);
+    });
kubabrecka wrote:
> dvyukov wrote:
> > kubabrecka wrote:
> > > dvyukov wrote:
> > > > This is exit which should terminate whole process. How is calling pthread_exit? Where? 
> > > pthread_exit is called immediately from dispatch_main below, not here.
> > I am confused. You do "// CHECK: Done.", so NSLog is executed. But then exit is not executed? And this is executed on the main thread? How does dispatch_main calls pthread_exit while we are blocked in sleep in the very same thread? From a signal handler? Why does it do it?
> > I seem to be missing something.
> This is not executed on the main thread, the main thread is terminated from dispatch_main.  This gets executed on a different thread, but technically still on the "main queue".
Calling dispatch_main() from the main thread basically says:  "I'm not using the main thread for anything else that libdispatch stuff."  So libdispatch knows it's safe to treat the main queue as a "regular serial queue", exit the main thread and schedule stuff dispatched to the main queue on worker threads (but still in a serial, synchronized manner).


More information about the llvm-commits mailing list