mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-07-26 06:38:42 +00:00
ci: try to fix race condition in testdata/goroutines.go
A race condition was possible because the 'acquire' goroutine might not have started in 4 milliseconds which changed the ordering of the test. This patch fixes it by making sure the goroutine has started (and locked the mutex) before continuing with the test.
This commit is contained in:
committed by
Ron Evans
parent
3f8a110e4a
commit
25b83920b6
Vendored
+6
-2
@@ -62,12 +62,15 @@ func main() {
|
||||
time.Sleep(2 * time.Millisecond)
|
||||
|
||||
var m sync.Mutex
|
||||
var wg sync.WaitGroup
|
||||
m.Lock()
|
||||
println("pre-acquired mutex")
|
||||
go acquire(&m)
|
||||
wg.Add(1)
|
||||
go acquire(&m, &wg)
|
||||
time.Sleep(2 * time.Millisecond)
|
||||
println("releasing mutex")
|
||||
m.Unlock()
|
||||
wg.Wait()
|
||||
time.Sleep(2 * time.Millisecond)
|
||||
m.Lock()
|
||||
println("re-acquired mutex")
|
||||
@@ -89,8 +92,9 @@ func main() {
|
||||
<-done
|
||||
}
|
||||
|
||||
func acquire(m *sync.Mutex) {
|
||||
func acquire(m *sync.Mutex, wg *sync.WaitGroup) {
|
||||
m.Lock()
|
||||
wg.Done()
|
||||
println("acquired mutex from goroutine")
|
||||
time.Sleep(2 * time.Millisecond)
|
||||
println("releasing mutex from goroutine")
|
||||
|
||||
Reference in New Issue
Block a user