Created
July 21, 2018 06:21
-
-
Save hauxe/e5a170f1deaff348c2217c23149d6139 to your computer and use it in GitHub Desktop.
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
package main | |
import ( | |
"log" | |
"sync" | |
) | |
func main() { | |
cond := sync.NewCond(&sync.Mutex{}) | |
var wg1 sync.WaitGroup | |
var wg2 sync.WaitGroup | |
wg1.Add(1) | |
wg2.Add(1) | |
go func() { | |
defer wg2.Done() | |
wg1.Done() | |
cond.L.Lock() | |
defer cond.L.Unlock() | |
cond.Wait() | |
log.Println("I received notification!") | |
}() | |
wg1.Wait() | |
cond.Signal() | |
wg2.Wait() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment