This patch fixes the custom ThreadState destruction on OS X to avoid crashing when dispatch_main calls pthread_exit which quits the main thread.
Details
Diff Detail
Event Timeline
test/tsan/Darwin/dispatch_main.mm | ||
---|---|---|
28 | 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? |
test/tsan/Darwin/dispatch_main.mm | ||
---|---|---|
28 | 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". |
test/tsan/Darwin/dispatch_main.mm | ||
---|---|---|
28 | 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). |
LGTM. But please document how pthread_exit gets called on the main thread and change sleep(3) to sleep(1) which should be enough to catch the crash in most executions.
Why do we need this sleep? Can we remove it? Can we use the invisible barrier instead?
This test will run for 3 seconds. I would like to reduce it's duration.