forked from NebulousLabs/Sia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
separate ThreadGroup locking by function
The threadgroup has two separate things that it is protecting when it locks the mutex. One group of things is to block the execution of other threads, in the case of 'Add', 'Flush', and 'Stop'. The other group of things is to protect the ThreadGroup state variables, namely 'onStopFns' and 'afterStopFns'. Previously, you would get a deadlock with the following: tg.Add() go func { tg.Stop() } time.Sleep(1 * time.Second) tg.OnStop() tg.Done() The deadlock happens because tg.Stop() is blocking the OnStop call while it waits for the tg.Add to return, but the tg.Add will not return until tg.OnStop can get the lock. I don't see any reason for this behavior to be forbidden. You want to be able to do something like: tg.Add() tg.RegisterRPC() tg.OnStop(func() { tg.UnregisterRPC() }) tg.Done() and currently that's not safe code if you are assuming that Stop() could be called at any time.
- Loading branch information
1 parent
2856326
commit 3ffc5b3
Showing
2 changed files
with
63 additions
and
7 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