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

parallel: remove mutex from Map and Times #13

Merged
merged 2 commits into from
Mar 5, 2022
Merged

parallel: remove mutex from Map and Times #13

merged 2 commits into from
Mar 5, 2022

Conversation

fsouza
Copy link
Contributor

@fsouza fsouza commented Mar 5, 2022

The slice is pre-allocated, a mutex is not needed.

var wg sync.WaitGroup
wg.Add(len(collection))

for i, item := range collection {
go func (_item T, _i int) {
go func(_item T, _i int) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

includes some fixes by gofmt, let me know if you'd prefer me to remove those

The slice is pre-allocated, a mutex is not needed.
@samber
Copy link
Owner

samber commented Mar 5, 2022

oh yes!

Since result is allocated earlier, we do not need locks anymore...

I will run benchmarks again.

@samber samber merged commit ab4e214 into samber:master Mar 5, 2022
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