Standard library / sync
sync.Mutex.TryLock()
Attempt to acquire without waiting. A failed attempt establishes no synchronization and grants no access to protected state. Expected stdout: 'false\n'.
Formal Syntax & Structure
go syntaxgo
func (m *Mutex) TryLock() boolReturn Value
bool
Whether the lock was acquired.
Working Example
Example Snippetgo
package main
import ( "fmt" "sync")
func main() { var m sync.Mutex; m.Lock(); fmt.Println(m.TryLock()); m.Unlock() }