Code Room
Code reviewHard
Question
Review this Go bounded semaphore used to cap concurrent uploads. Workers call Acquire before an upload and Release after.
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 Sem struct { mu sync.Mutex cond *sync.Cond avail int} func NewSem(n int) *Sem { s := &Sem{avail: n} s.cond = sync.NewCond(&s.mu) return s} func (s *Sem) Acquire() { s.mu.Lock() if s.avail == 0 { s.cond.Wait() } s.avail-- s.mu.Unlock()} func (s *Sem) Release() { s.mu.Lock() s.avail++ s.cond.Signal() s.mu.Unlock()}Run or narrate your approach, then ask the coach.