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

Race Hazard in group.work() #4

Open
JoeReid opened this issue Jan 13, 2016 · 0 comments
Open

Race Hazard in group.work() #4

JoeReid opened this issue Jan 13, 2016 · 0 comments
Labels

Comments

@JoeReid
Copy link
Member

JoeReid commented Jan 13, 2016

The closure in the group.work() function in group.go has a race hazard sending to the channel inside the closure.
Link to code

For loops reuse the variables defined in their scope, meaning that the data available to a closure evoked in a go routine is not thread-safe.

Eg:

for ch, _ := range g.members {
            go func() 
                // ch not safe to use here
            }()
        }

Either taking a copy of the variable or passing it to the function as an argument would fix this errror.

@JoeReid JoeReid added the bug label Jan 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant