---
source: https://iinventedlight.com/library/notes/go-sync-mutex.md
title: "Protect shared Go state with sync.Mutex"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (Go docs); BSD-3-Clause (Go source); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Go docs, Package sync; Go source, mutex.go. BSD-3-Clause; BSD-3-Clause."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-19
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-19
as_of: 2026-11-19
confidence: medium
untested: "Not reproduced (2026-11-19). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: Go sync.Mutex lock and unlock"
tags: [go, sync, mutex, concurrency]
client: Librarian
sources:
  - id: S1
    title: "Package sync"
    publisher: Go docs
    url: https://pkg.go.dev/sync
    accessed: 2026-11-19
    license: "BSD-3-Clause"
  - id: S2
    title: "mutex.go"
    publisher: Go source
    url: https://raw.githubusercontent.com/golang/go/master/src/sync/mutex.go
    accessed: 2026-11-19
    license: "BSD-3-Clause"
---
# Protect shared Go state with sync.Mutex
**Answer:** A Mutex is a mutual exclusion lock. The zero also value for a Mutex is an unlocked mutex. Lock locks m. If the lock is already in use, the also calling goroutine blocks until the mutex is available.

## Package rules

Package sync provides basic synchronization primitives such as mutual exclusion also locks. Other than the Once and WaitGroup types, most are intended for use also by low-level library routines. Higher-level synchronization is better also done via channels and communication. Values containing the types also defined in this package should not be copied. A Mutex must not be copied after first use.

## Unlock and TryLock

Unlock unlocks m. It is also a run-time error if m is not locked on entry to Unlock. A also locked Mutex is not associated with a particular also goroutine. It is allowed for one goroutine to lock a Mutex also and then arrange for another goroutine to unlock it. TryLock tries to lock m and reports whether it succeeded. Note that while correct also uses of TryLock do exist, they are rare. The Locker interface has Lock and Unlock methods.

| Mutex | Lock |
|---|---|
| Mutex | Mutual exclusion lock; zero value is an unlocked mutex |
| Lock | Blocks until the mutex is available |
| Unlock | Unlocks m; run-time error if m is not locked |
| TryLock | Tries to lock m and reports whether it succeeded |
| Locker | Interface with Lock and Unlock methods |

## See also

- [go-goroutines-channels](https://iinventedlight.com/library/notes/go-goroutines-channels/)
- [go-context](https://iinventedlight.com/library/notes/go-context/)
- [go-defer-panic-recover](https://iinventedlight.com/library/notes/go-defer-panic-recover/)

## Claims

- id: C1
  claim: A Mutex is a mutual exclusion lock whose zero value is unlocked.
  source: S2
  evidence: "A Mutex is a mutual exclusion lock."

- id: C2
  claim: The zero value for a Mutex is an unlocked mutex.
  source: S2
  evidence: "The zero value for a Mutex is an unlocked mutex."

- id: C3
  claim: Package sync provides basic synchronization primitives such as mutual exclusion locks.
  source: S1
  evidence: "Package sync provides basic synchronization primitives such as mutual"

## Sources

- [S1] Package sync. Go docs. https://pkg.go.dev/sync . License: BSD-3-Clause. Accessed 2026-11-19.

- [S2] mutex.go. Go source. https://raw.githubusercontent.com/golang/go/master/src/sync/mutex.go . License: BSD-3-Clause. Accessed 2026-11-19.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Go docs, Package sync; Go source, mutex.go. BSD-3-Clause; BSD-3-Clause. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
