These Go sync package questions cover Mutex, RWMutex, WaitGroup, Once, sync/atomic, sync.Map, sync.Pool and sync.Cond. We gathered them from public interview lists, coding rounds and community threads. Then we rewrote them in plain words and grouped them by tool.
This post is questions only, so answer each one in your own words first. When you need help, read Go sync package: WaitGroup and Mutex and Go race detector. Also, finish Part 15 on channels first, because you should know when a channel fits better than a lock.
How to Use These Go Sync Package Questions
Answer each of these Go sync package questions out loud, then write a tiny program and run it with -race. Lock bugs usually appear only under load, so small tests with many goroutines help a lot. Finally, try the scenario questions, since they come from real production issues.
The table below lists each section and its number of questions.
| Section | What it tests | Questions |
|---|---|---|
| Mutex basics | Lock, defer and copy rules | 15 |
| RWMutex and design | Readers, writers and lock order | 14 |
| WaitGroup and Once | Waiting for work and running once | 15 |
| sync/atomic | Atomic types, CAS and Pointer | 14 |
| Map, Pool and Cond | Special tools for narrow cases | 15 |
| Sync coding tasks | Classic interview programs | 14 |

Go Sync Package Questions on Mutex
Before you answer, study Go sync package: WaitGroup and Mutex. These Go sync package questions start with the Mutex, because most shared state in Go uses one.
- What is a sync.Mutex, and what problem does it solve?
- Why is the zero value of a Mutex ready to use?
- Why should you release a lock with defer right after you take it?
- When is it better not to use defer, for example in a tight loop?
- Is a Go Mutex reentrant, and what happens when one goroutine locks it twice?
- Why must you never copy a Mutex after first use?
- How does go vet catch a copied lock?
- Should a Mutex be a named field or an embedded field, and why?
- Where should the Mutex sit in a struct, next to the fields it guards?
- What does TryLock do, and why do the docs say to use it rarely?
- What is starvation mode in the Go Mutex?
- How do you keep the critical section as small as possible?
- Why is calling an unknown callback while holding a lock risky?
- Scenario: when a method with a value receiver locks a Mutex and the data still races, what went wrong?
- Scenario: when a service slows down because many goroutines wait for one lock, how would you find and fix it?
Go Sync Package Questions on RWMutex and Lock Design
Before you answer, study Go in-memory cache with TTL, because a cache is the classic place for an RWMutex. These Go sync package questions test design, so explain the trade-off behind each answer.
- What is an RWMutex, and how do RLock and Lock differ?
- When does an RWMutex beat a plain Mutex, and when is it slower?
- What happens to new readers while a writer waits for the lock?
- Can you upgrade a read lock to a write lock in Go?
- Why can a recursive read lock deadlock when a writer is waiting?
- What is lock ordering, and how does it prevent deadlocks?
- How does sharding a map into many locked parts reduce waiting?
- When should you use a channel instead of a lock?
- How do you protect a slice that many goroutines append to?
- Why should getters return copies of slices instead of the guarded slice itself?
- How do you test that a type is safe for concurrent use?
- How do mutex profiles in pprof show lock waiting time?
- Scenario: when a read-heavy cache uses a Mutex and CPU is high, how would you decide whether to switch to RWMutex?
- Scenario: when two services each hold one lock and wait for the other, how would you redesign the locking?
Go Sync Package Questions on WaitGroup and Once
Before you answer, study Go worker pool pattern. WaitGroup and Once look simple, yet many Go sync package questions hide traps inside them.
- What do Add, Done and Wait do on a WaitGroup?
- Why must Add happen before the goroutine starts?
- What happens when the code calls Done more times than Add?
- Can you reuse a WaitGroup after Wait returns?
- What does WaitGroup.Go add in Go 1.25, and how does it simplify code?
- How do you wait for a WaitGroup with a timeout?
- What does sync.Once guarantee, even with many goroutines?
- What happens if the function passed to Once.Do panics?
- Can a Once run its function again after an error, and what is the workaround?
- What do sync.OnceFunc, sync.OnceValue and sync.OnceValues add since Go 1.21?
- Why is Once a good fit for lazy setup of a shared client?
- How is Once different from an init function?
- Why does calling Once.Do from inside the same function deadlock?
- Scenario: when a lazy database connection must open once but can fail, how would you design it?
- Scenario: when a program sometimes exits before the last worker logs its result, what would you check?
Go Sync Package Questions on sync/atomic
Before you answer, study Go race detector again. Atomics are fast but easy to misuse, so these Go sync package questions ask where they stop being enough.
- What does the sync/atomic package give you?
- When is an atomic counter better than a Mutex?
- What types did Go 1.19 add, such as atomic.Int64 and atomic.Bool?
- Why are the new atomic types safer than the old functions on plain ints?
- What does CompareAndSwap do, and how do you build a retry loop with it?
- How does atomic.Pointer help you swap a whole config at once?
- What is atomic.Value, and what limit does it have on types?
- Why can two separate atomic operations still race as a pair?
- How do atomics fit into the Go memory model?
- Why is a 64-bit atomic on 32-bit platforms a special case in old code?
- Can you mix atomic and normal reads on the same variable?
- How do you read a flag that another goroutine sets with an atomic store?
- Scenario: when a hot counter with a Mutex shows up in a CPU profile, how would you replace it?
- Scenario: when a feature flag must change at run time without a restart, how would you store it?
sync.Map, sync.Pool and sync.Cond
Before you answer, study Go garbage collector and memory. These three tools solve narrow problems, so these Go sync package questions test when to pick them.
- What is sync.Map, and how is it different from a map with a Mutex?
- For which two access patterns do the docs suggest sync.Map?
- Why does sync.Map use any for keys and values, and what does that cost?
- What do LoadOrStore and LoadAndDelete do?
- How do you count the items in a sync.Map?
- What is sync.Pool, and what kind of objects belong in it?
- Why can the garbage collector drop objects from a Pool at any time?
- Why should you reset a buffer before you put it back in a Pool?
- When does a Pool make things slower instead of faster?
- What is sync.Cond, and what do Wait, Signal and Broadcast do?
- Why must Wait run inside a loop that checks the condition?
- Why do many Go developers use channels instead of sync.Cond?
- How would you build a bounded queue with sync.Cond?
- Scenario: when a JSON service allocates a new buffer for every request, how would you reuse them?
- Scenario: when a team replaces every map with sync.Map, how would you review the change?
Go Sync Package Questions for Coding Rounds
Before you answer, write each program by hand and run it with -race. Interviewers watch where you take and release locks, not only whether the code runs.
- Write a safe counter type with Inc and Value methods.
- Build a thread-safe cache with Get and Set using RWMutex.
- Fix a program that copies a struct holding a Mutex.
- Use sync.Once to create a single shared HTTP client.
- Count page hits from many goroutines with atomic.Int64.
- Swap a config pointer at run time with atomic.Pointer.
- Count unique visitors from many goroutines with sync.Map.
- Reuse bytes.Buffer objects with sync.Pool.
- Build a bounded queue with sync.Cond and two methods.
- Write a bank account with Deposit and Withdraw that never goes below zero.
- Transfer money between two accounts without deadlock.
- Print numbers in order from three goroutines using only a Mutex and a counter.
- Scenario: when an interviewer asks for a rate counter per user, how would you lock it without one global lock?
- Scenario: when a bank transfer locks two accounts, how would you choose the lock order?
Code Reading Questions
Read each program carefully and predict the output before you run it. Then explain the result in your own words.
package main
import (
"fmt"
"sync"
)
var (
once sync.Once
config map[string]string
)
func loadConfig() {
fmt.Println("loading config")
config = map[string]string{"env": "prod"}
}
var port = sync.OnceValue(func() int {
fmt.Println("reading port")
return 8080
})
func main() {
var wg sync.WaitGroup
for range 3 {
wg.Add(1)
go func() {
defer wg.Done()
once.Do(loadConfig)
}()
}
wg.Wait()
fmt.Println(config["env"])
fmt.Println(port(), port())
}
- How many times does loading config print, and why is reading config after Wait safe?
- What does the last line print, and how many times does reading port appear?
The second program counts hits with an atomic type and unique users with sync.Map.
package main
import (
"fmt"
"sync"
"sync/atomic"
)
func main() {
var hits atomic.Int64
var seen sync.Map
var wg sync.WaitGroup
users := []string{"asha", "ravi", "asha", "meera", "ravi", "asha"}
for _, u := range users {
wg.Add(1)
go func(name string) {
defer wg.Done()
hits.Add(1)
seen.LoadOrStore(name, true)
}(u)
}
wg.Wait()
unique := 0
seen.Range(func(_, _ any) bool {
unique++
return true
})
fmt.Println(hits.Load(), unique)
var state atomic.Int32
fmt.Println(state.CompareAndSwap(0, 1), state.CompareAndSwap(0, 2), state.Load())
}
- What two numbers does the first line print, and why is the result the same on every run?
- Why does the second CompareAndSwap return false, and what is the final state?
Quick Revision Table for the sync Package
Use the table below as a final check before your interview. It maps each tool to the job it does best.
| Tool | Best for | Watch out for |
|---|---|---|
| sync.Mutex | Guarding shared fields | Copying it, long critical sections |
| sync.RWMutex | Read-heavy data | No upgrade from read to write |
| sync.WaitGroup | Waiting for a set of goroutines | Add before go, never below zero |
| sync.Once | One-time setup | A panic still counts as done |
| sync/atomic | Counters and flags | Two ops are not atomic together |
| sync.Map | Stable keys, many readers | Type safety and counting items |
| sync.Pool | Reusing short-lived buffers | Objects can vanish at GC |
Also, many interviewers ask you to compare Mutex and RWMutex directly. The diagram below shows the difference side by side.

Official Resources
These official pages explain the rules behind these questions.
- Package sync documentation
- Package sync/atomic documentation
- The Go Memory Model
- A Tour of Go: sync.Mutex
Quick Recap
- These Go sync package questions cover Mutex, RWMutex, WaitGroup, Once, atomics, sync.Map, Pool and Cond.
- Release every lock with defer, and never copy a struct that holds a lock.
- Use RWMutex only when reads clearly outnumber writes.
- Once runs setup exactly one time, and OnceValue returns a cached result.
- Atomic types suit single counters and flags, while a Mutex guards groups of fields.
- Pick sync.Map and sync.Pool only for the narrow cases the docs describe.
What’s Next?
By now, you have Go sync package questions for every tool in the sync package. Study the answers in your own notes, then check them against the Go interview topics study guide.


