# panic: sync: mutex is locked

- **ID:** `go/mutex-copied-after-use`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A sync.Mutex or other sync primitive is copied after use, causing the lock state to be duplicated and leading to deadlock or panic when the copy is used.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.20 | active | — | — |
| 1.21 | active | — | — |

## Workarounds

1. **** (98% success)
   ```
   type SafeCounter struct {
    mu sync.Mutex
    v  int
}

func (c *SafeCounter) Inc() {
    c.mu.Lock()
    c.v++
    c.mu.Unlock()
}

// Always use *SafeCounter, never copy the struct.
   ```
2. **** (95% success)
   ```
   type Counter struct {
    mu *sync.Mutex
    v  int
}

func NewCounter() *Counter {
    return &Counter{mu: &sync.Mutex{}}
}

func (c *Counter) Inc() {
    c.mu.Lock()
    c.v++
    c.mu.Unlock()
}
   ```

## Dead Ends

- **** — The panic will recur unpredictably; it's a fundamental design flaw. (100% fail)
- **** — Copying a mutex is illegal; it cannot be safely copied at all. (100% fail)
