1
0
mirror of https://github.com/chai2010/advanced-go-programming-book.git synced 2025-05-24 12:32:21 +00:00

change unlock logic in trylock example

This commit is contained in:
Xargin 2018-08-03 14:29:47 +08:00
parent 9b6a55d791
commit 4df729f54b

View File

@ -102,14 +102,8 @@ func (l Lock) Lock() bool {
} }
// Unlock , Unlock the try lock // Unlock , Unlock the try lock
func (l Lock) Unlock() bool { func (l Lock) Unlock() {
unlockResult := false l.c <- struct{}{}
select {
case l.c <- struct{}{}:
unlockResult = true
default:
}
return unlockResult
} }
var counter int var counter int