Skip to content

Instantly share code, notes, and snippets.

@teivah
Created August 24, 2022 08:21
Show Gist options
  • Select an option

  • Save teivah/c65fcbae3a9431903bf4fafaf09a85e5 to your computer and use it in GitHub Desktop.

Select an option

Save teivah/c65fcbae3a9431903bf4fafaf09a85e5 to your computer and use it in GitHub Desktop.
func parallelMergesortV1(s []int) {
if len(s) <= 1 {
return
}
middle := len(s) / 2
var wg sync.WaitGroup
wg.Add(2)
go func() { // Spins up the first half of the work in a goroutine
defer wg.Done()
parallelMergesortV1(s[:middle])
}()
go func() { // Spins up the second half of the work in a goroutine
defer wg.Done()
parallelMergesortV1(s[middle:])
}()
wg.Wait()
merge(s, middle) // Merges the halves
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment