-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent pthread startup hangs (#411)
The hang scenario is as follows: 1. thread A starts executing a pthread function, which takes a critical pthread lock. 2. thread B is creating a new thread, and enters thread creation/busy state. It tries to take the same lock, and pauses. 3. thread C starts a collection, and signals all threads 4. thread A pauses waiting for the resume signal with the lock held 5. deadlock -- thread A holds the critical lock. Thread B cannot continue, but is in a busy state (sets state to Delayed). Thread C is waiting for all threads to leave the busy state. The solution is to absolutely forbid sending signals while a thread is starting. In order to achieve this, we allocate a bit of the `startingThreadCount` atomic uint. If this bit is set, it means a thread has taken the lock, and crucially, when it was set *no threads were starting*. Any thread that then starts will increment `startingThreadCount`, but find the bit is set. If the bit is set, and it's not the thread that is running the collection (the collection thread is allowed to start worker threads), then the `stopTheWorld` lock is taken to pause that thread until the collection is over. The thread stopping the world is now free to send signals to all threads, knowing that there will be no thread that is in the critical stage of starting up.
- Loading branch information
Showing
3 changed files
with
48 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters