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
- Repository
- rL LLVM
Event Timeline
test/tsan/Darwin/dispatch_main.mm | ||
---|---|---|
27 ↗ | (On Diff #51729) | Why do we need this sleep? Can we remove it? Can we use the invisible barrier instead? |
28 ↗ | (On Diff #51729) | This is exit which should terminate whole process. How is calling pthread_exit? Where? |
test/tsan/Darwin/dispatch_main.mm | ||
---|---|---|
28 ↗ | (On Diff #51729) | 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 ↗ | (On Diff #51729) | 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 ↗ | (On Diff #51729) | 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.