Code RoomMutex copied by value receiver
HardPrep Room Coding #1868

Mutex copied by value receiver

Code reviewConcurrencySenior–Staff~40 min

Review this Go counter type.

`go vet` complains. What is actually wrong?

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 40 min
Mark a line and say what kind of problem it is.0 findings
1type Counter struct {
2 mu sync.Mutex
3 n int
4}
5 
6func (c Counter) Inc() { // (1) value receiver
7 c.mu.Lock()
8 c.n++
9 c.mu.Unlock()
10}
11 
12func (c Counter) Value() int { // (2) value receiver
13 c.mu.Lock()
14 defer c.mu.Unlock()
15 return c.n
16}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.