loong / go-concurrency-exercises

Hands on exercises with real-life examples to study and practice Go concurrency patterns. Test-cases are provided to verify your answers.
Other
1.17k stars 401 forks source link

Fixing a minor bug in Excercise 4 #38

Closed jabielecki closed 5 months ago

jabielecki commented 10 months ago

This fixes a race happening in the mock of 4-graceful-sigint:

$ cd 4-graceful-sigint
$ go run -race .
Process running...^C==================
WARNING: DATA RACE
Read at 0x00c00001415f by goroutine 10:
  main.(*MockProcess).Stop()
      4-graceful-sigint/mockprocess.go:34 +0x30
  main.main.func3()
      4-graceful-sigint/main.go:38 +0x33

Previous write at 0x00c00001415f by goroutine 9:
  main.(*MockProcess).Run()
      4-graceful-sigint/mockprocess.go:22 +0x30
  main.main.func2()
      4-graceful-sigint/main.go:31 +0x33

Goroutine 10 (running) created at:
  main.main()
      4-graceful-sigint/main.go:38 +0x267

Goroutine 9 (running) created at:
  main.main()
      4-graceful-sigint/main.go:31 +0x165
==================

Functionality not changed.

boooec commented 5 months ago

@loong =)