-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #331 from hearchco/as/fix/algo
fix(search): forgot a case when no workers return for a origin
- Loading branch information
Showing
5 changed files
with
65 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package search | ||
|
||
import ( | ||
"sync" | ||
) | ||
|
||
// Waits on either c.Wait() or wg.Wait() to do final.Done(). | ||
func waitForSuccessOrFinish(c *sync.Cond, wg *sync.WaitGroup, final *sync.WaitGroup) { | ||
defer final.Done() | ||
d := sync.Cond{L: &sync.Mutex{}} | ||
|
||
// Wait for signal from any successful worker. | ||
go func() { | ||
c.L.Lock() | ||
c.Wait() | ||
c.L.Unlock() | ||
|
||
d.L.Lock() | ||
d.Signal() | ||
d.L.Unlock() | ||
}() | ||
|
||
// Wait for all workers to finish (even if it's unsuccessful). | ||
go func() { | ||
wg.Wait() | ||
|
||
d.L.Lock() | ||
d.Signal() | ||
d.L.Unlock() | ||
}() | ||
|
||
// Whichever of the above finishes first, signal the final wait group. | ||
d.L.Lock() | ||
d.Wait() | ||
d.L.Unlock() | ||
} |
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