Skip to content

Instantly share code, notes, and snippets.

@hauxe
Created July 21, 2018 06:21
Show Gist options
  • Save hauxe/e5a170f1deaff348c2217c23149d6139 to your computer and use it in GitHub Desktop.
Save hauxe/e5a170f1deaff348c2217c23149d6139 to your computer and use it in GitHub Desktop.
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