Skip to content

Commit f383714

Browse files
Fixed potential issue on single core machine.
1 parent b6079a3 commit f383714

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)