Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync: spurious wakeup from WaitGroup.Wait #7734

Closed
rui314 opened this issue Apr 8, 2014 · 5 comments
Closed

sync: spurious wakeup from WaitGroup.Wait #7734

rui314 opened this issue Apr 8, 2014 · 5 comments
Milestone

Comments

@rui314
Copy link
Member

rui314 commented Apr 8, 2014

What does 'go version' print?
go version devel +519230b4d06a Sun Apr 06 10:30:02 2014 -0400 + linux/amd64

What steps reproduce the problem?
The following program, which uses a WaitGroup to wait for two goroutines to complete,
should never exit.

package main

import (
        "fmt"
        "runtime"
        "sync"
        "sync/atomic"
)

func main() {
        for i := int64(0); ; i++ {
                wg := &sync.WaitGroup{}
                wg.Add(1)
                counter := int32(0)
                // spawn goroutine 1                                                                                                                        
                go func() {
                        atomic.AddInt32(&counter, 1)
                        wg.Done()
                }()
                runtime.Gosched()
                wg.Add(1)
                // spawn goroutine 2                                                                                                                        
                go func() {
                        atomic.AddInt32(&counter, 1)
                        wg.Done()
                }()
                // Wait for goroutine 1 and 2                                                                                                                   
                wg.Wait()
                if atomic.LoadInt32(&counter) != 2 {
                        fmt.Println(i, "Spurious wakeup from Wait()")
                        return
                }
        }
}

What happened?
It exits because of a bug in WaitGroup. (It may take a few minutes to fail.)

$ GOMAXPROCS=2 go run test.go
26994961 Spurious wakeup from Wait()
@rui314
Copy link
Member Author

rui314 commented Apr 8, 2014

Comment 1:

I have a fix for this, will send for review later.

@bradfitz
Copy link
Contributor

bradfitz commented Apr 8, 2014

Comment 2:

Confirmed the bug here on Linux. I agree that program shouldn't ever fail.

Labels changed: added release-go1.3, repo-main.

Status changed to Accepted.

@bradfitz
Copy link
Contributor

bradfitz commented Apr 8, 2014

Comment 3:

https://golang.org/cl/85580043/ was sent

Status changed to Started.

@gopherbot
Copy link

Comment 4:

CL https://golang.org/cl/85580043 references this issue.

@dvyukov
Copy link
Member

dvyukov commented Apr 10, 2014

Comment 5:

This issue was closed by revision e9347c7.

Status changed to Fixed.

@rsc rsc added this to the Go1.3 milestone Apr 14, 2015
@rsc rsc removed the release-go1.3 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants