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

Fix for multiple goroutines appending to slice, Solves #613 #639

Merged
merged 2 commits into from
May 6, 2016

Conversation

sselph
Copy link

@sselph sselph commented May 5, 2016

No description provided.

@@ -262,6 +262,7 @@ type changeSliceArg struct {
localParent, remoteParent string
dirList []*dirList
changeListPtr *[]*Change
mtx *sync.Mutex
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you make this instead a non-pointer value and drop the extra the indirection ie

mtx sync.Mutex

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also could we call it mu sync.Mutex?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changing to mu is fine. I'll send an update for that.

The non-pointer I think will be an issue. Each go routine needs to be using the same mutex to effectively communicate. So if I pass the mutex by value, I don't think they will be. I did a quick test and -race was still showing the race condition.

The other option would be to pass a channel and have the workers return values via the channel and add them to the list using a single routine.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh, gotcha. Aye aye, go for it. Thank you for investigating this.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant to say, you can keep the pointer version of it.

@odeke-em
Copy link
Owner

odeke-em commented May 5, 2016

Just posted a few comments otherwise LGTM! Thank you.

@sselph
Copy link
Author

sselph commented May 6, 2016

No problem it was fun getting to play with the race detector.

@odeke-em
Copy link
Owner

odeke-em commented May 6, 2016

LGTM! Thank you @sselph for this fix.

@odeke-em odeke-em merged commit ce0d292 into odeke-em:master May 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants