Skip to content

Commit 8ff933b

Browse files
Merge pull request #58 from Workiva/sort_single_cpu
Fixed potential issue on single core machine.
2 parents b6079a3 + f383714 commit 8ff933b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

sort/sort.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ func MultithreadedSortComparators(comparators Comparators) Comparators {
2525
copy(toBeSorted, comparators)
2626

2727
var wg sync.WaitGroup
28-
chunks := chunk(toBeSorted, int64(runtime.NumCPU()))
28+
29+
numCPU := int64(runtime.NumCPU())
30+
if numCPU%2 == 1 { // single core machine
31+
numCPU++
32+
}
33+
34+
chunks := chunk(toBeSorted, numCPU)
2935
wg.Add(len(chunks))
3036
for i := 0; i < len(chunks); i++ {
3137
go func(i int) {

0 commit comments

Comments
 (0)