# panic: sync: mutex is locked (copied value)

- **ID:** `go/mutex-copy-value`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A sync.Mutex (or other sync primitives) is copied by value after being locked. Mutexes should never be copied; copying a locked mutex leads to undefined behavior and can cause panics.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.0 | active | — | — |
| 1.1 | active | — | — |

## Workarounds

1. **Use a pointer to the struct that contains the mutex** (95% success)
   ```
   type SafeStruct struct {
    mu sync.Mutex
    data int
}
func NewSafeStruct() *SafeStruct {
    return &SafeStruct{}
}
   ```
2. **Embed the mutex as a pointer field** (90% success)
   ```
   type SafeStruct struct {
    mu   *sync.Mutex
    data int
}
func NewSafeStruct() *SafeStruct {
    return &SafeStruct{mu: &sync.Mutex{}}
}
   ```

## Dead Ends

- **Using a pointer to the mutex but still copying it** — If the struct containing the mutex is copied, the mutex is still copied even if it's a pointer field; the pointer itself is copied, but the underlying mutex is shared incorrectly. (85% fail)
- **Ignoring the panic and continuing execution** — The panic is fatal and will crash the program; ignoring it is not possible without recovery, and even then the mutex state is corrupted. (95% fail)
