-
-
Notifications
You must be signed in to change notification settings - Fork 505
Open
Labels
community mistakeMistakes proposed by the communityMistakes proposed by the community
Description
Use of Semaphores
First of all, let me say that this is amazing work correcting 100 Golang code mistakes while writing clean code. Thank you for your hard work. I am learning a lot.
Second, it is not an issue just an observation - wouldn't semaphores be the best solution for making concurrency more productive? The solution is to teach the best there is to teach about Golang right?
`const max = 2048 // Defines the threshold
func parallelMergesortV2(s []int) {
if len(s) <= 1 {
return
}
if len(s) <= max {
sequentialMergesort(s) // Calls our initial sequential version
} else { // If bigger than the threshold, keeps the parallel version
middle := len(s) / 2
var wg sync.WaitGroup
wg.Add(2)
go func() {
defer wg.Done()
parallelMergesortV2(s[:middle])
}()
go func() {
defer wg.Done()
parallelMergesortV2(s[middle:])
}()
wg.Wait()
merge(s, middle)
}
}`
Solution
I would recommend the use of semaphores
One or multiple solutions to avoid the mistake.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
community mistakeMistakes proposed by the communityMistakes proposed by the community