Follow these critical patterns when using locks to prevent deadlocks, resource leaks, and performance issues: 1. Use consistent lock naming: ```go // Prefer
Follow these critical patterns when using locks to prevent deadlocks, resource leaks, and performance issues:
// Prefer
taskTrackerLock sync.RWMutex
// Over
taskTrackerMu sync.RWMutex
// Good func (s *Service) ProcessData() { response := s.client.Call() // Do I/O first
s.lock.Lock()
defer s.lock.Unlock()
// Only use lock for quick state updates } ```
if !timer.Stop() {
select {
case <-timer.C: // drain the channel if fired
default:
}
}
s.lock.Lock() defer s.lock.Unlock()
select { case <-ctx.Done(): return ctx.Err() case <-s.workChan: // Process work } ```
Enter the URL of a public GitHub repository