Created
April 28, 2018 03:37
-
-
Save sadlil/412b301115f6c5b2959f1244fc1c85bf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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