From f383714ebf458d8c64365262ef23c01a2d47f335 Mon Sep 17 00:00:00 2001 From: Dustin Hiatt Date: Tue, 10 Feb 2015 07:57:36 -0600 Subject: [PATCH] Fixed potential issue on single core machine. --- sort/sort.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sort/sort.go b/sort/sort.go index 576b523..3b949d5 100644 --- a/sort/sort.go +++ b/sort/sort.go @@ -25,7 +25,13 @@ func MultithreadedSortComparators(comparators Comparators) Comparators { copy(toBeSorted, comparators) var wg sync.WaitGroup - chunks := chunk(toBeSorted, int64(runtime.NumCPU())) + + numCPU := int64(runtime.NumCPU()) + if numCPU%2 == 1 { // single core machine + numCPU++ + } + + chunks := chunk(toBeSorted, numCPU) wg.Add(len(chunks)) for i := 0; i < len(chunks); i++ { go func(i int) {