sync.Map: a map safe for concurrent goroutines
Answer: Map is safe for concurrent use by multiple goroutines. Loads, stores, and deletes run in amortized constant time. A Map must not be copied after first use. The zero Map is empty and ready for use.
When to use Map
Map is like a Go map of any to any, and multiple goroutines may use it concurrently without additional locking or coordination.
The type is specialized. For better type safety, most code should keep a plain Go map and add separate locking or coordination.
A better fit is a key written once and then read many times, as in a cache that only grows, or several goroutines that read, write, and overwrite disjoint sets of keys.
Those patterns can reduce lock contention versus pairing a Go map with a Mutex or RWMutex.
Methods
Load returns the value stored for a key, or nil if no value is present. The ok result indicates whether the value was found.
Store sets the value for a key.
Delete deletes the value for a key, and does nothing when the key is not in the map.
LoadOrStore returns the existing value for a present key. Otherwise it stores the given value and returns that.
Range calls a function sequentially for each key and value present.
Clear deletes all the entries, resulting in an empty Map.
See also
Claims
- id: C1 claim: A Map is safe for concurrent use by multiple goroutines without additional locking. source: S1 evidence: "safe for concurrent use by multiple goroutines without additional locking"
- id: C2 claim: Loads, stores, and deletes run in amortized constant time. source: S1 evidence: "Loads, stores, and deletes run in amortized constant time"
- id: C3 claim: The zero Map is empty and ready for use. source: S2 evidence: "The zero Map is empty and ready for use"
- id: C4 claim: A Map must not be copied after first use. source: S2 evidence: "A Map must not be copied after first use"
- id: C5 claim: Load returns the stored value, or nil if none is present. source: S1 evidence: "or nil if no value is present"
Sources
- [S1] sync package reference. Go. https://pkg.go.dev/sync . License: BSD-3-Clause. Accessed 2026-11-23.
- [S2] sync/map.go source. Go. https://go.dev/src/sync/map.go . License: BSD-3-Clause. Accessed 2026-11-23.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Go, sync package reference; Go, sync/map.go source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Go, sync package reference; Go, sync/map.go source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors.
Cite this
iinventedlight. 2026. "sync.Map: a map safe for concurrent goroutines." iinventedlight Library, iil:note:h3mpggn8, version of 2026-11-23. https://iinventedlight.com/library/notes/go-sync-map/. License: CC-BY-4.0.
@misc{iil_note_h3mpggn8,
author = {{iinventedlight}},
title = {{sync.Map: a map safe for concurrent goroutines}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-23},
url = {https://iinventedlight.com/library/notes/go-sync-map/},
note = {Permanent ID iil:note:h3mpggn8. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- go-sync-map.schema.json (schema; CC-BY-4.0)
- go-sync-map.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-sync-map.md.