Skip to content

Instantly share code, notes, and snippets.

@sadlil
Created April 28, 2018 03:37
Show Gist options
  • Select an option

  • Save sadlil/412b301115f6c5b2959f1244fc1c85bf to your computer and use it in GitHub Desktop.

Select an option

Save sadlil/412b301115f6c5b2959f1244fc1c85bf to your computer and use it in GitHub Desktop.
var m1, m2 sync.Mutex
func main() {
  var wg sync.WaitGroup
 
wg.Add(1)
go func() {
defer wg.Done()
  m1.Lock()
  time.Sleep(time.Second * 2)
  m2.Lock()
  }()
 
wg.Add(1)
  go func() {
defer wg.Done()
  m2.Lock()
  time.Sleep(time.Second * 3)
  m1.Lock()
  }()
  wg.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment