Code Room
Code reviewHard
Question
Review this Go cache with a read-then-upgrade pattern.
What's the concurrency bug?
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.
Learn the concepts
type Cache struct { mu sync.RWMutex data map[string]int} func (c *Cache) GetOrCompute(k string) int { c.mu.RLock() if v, ok := c.data[k]; ok { c.mu.RUnlock() return v } // not found: upgrade to write lock while still holding the read lock c.mu.Lock() // (1) defer c.mu.Unlock() v := compute(k) c.data[k] = v c.mu.RUnlock() return v}Run or narrate your approach, then ask the coach.