We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 938ce22 commit 172c1d2Copy full SHA for 172c1d2
src/sync/mutex.go
@@ -32,9 +32,21 @@ func (m *Mutex) Unlock() {
32
// Wake up a blocked task, if applicable.
33
if t := m.blocked.Pop(); t != nil {
34
scheduleTask(t)
35
- } else {
36
- m.locked = false
37
}
+ m.locked = false
+}
38
+
39
+// TryLock tries to lock m and reports whether it succeeded.
40
+//
41
+// Note that while correct uses of TryLock do exist, they are rare,
42
+// and use of TryLock is often a sign of a deeper problem
43
+// in a particular use of mutexes.
44
+func (m *Mutex) TryLock() bool {
45
+ if m.locked {
46
+ return false
47
+ }
48
+ m.Lock()
49
+ return true
50
51
52
type RWMutex struct {
0 commit comments