Skip to content

Commit

Permalink
Fix data race
Browse files Browse the repository at this point in the history
  • Loading branch information
bahlo committed Aug 27, 2015
1 parent f195179 commit bc96e72
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions concurrency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,19 @@ func TestParallelTiming(t *testing.T) {
counter := 0

go Parallel(4, func(n int) {
time.Sleep(time.Duration(n) * time.Millisecond)
time.Sleep(time.Duration(10*n) * time.Millisecond)
m.Lock()
counter++
m.Unlock()
})

done := make(chan bool)
time.AfterFunc(2*time.Millisecond, func() {
time.AfterFunc(25*time.Millisecond, func() {
m.Lock()
if counter != 2 {
t.Errorf("Expected counter to be %d, but got %d", 2, counter)
}
m.Unlock()
done <- true
})

Expand Down

0 comments on commit bc96e72

Please sign in to comment.