Canonical guidance

Use when

Avoid

Preferred pattern

func TestCounter(t *testing.T) {
	var mu sync.Mutex
	var n int
	var wg sync.WaitGroup

	for i := 0; i < 4; i++ {
		wg.Add(1)
		go func() {
			defer wg.Done()
			mu.Lock()
			n++
			mu.Unlock()
		}()
	}

	wg.Wait()
	if n != 4 {
		t.Fatalf("n = %d, want 4", n)
	}
}

Anti-pattern

Explanation: This anti-pattern is common under schedule pressure, but timing hacks make tests pass while the underlying synchronization bug remains.

Why

Sources