--- /dev/null
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build !race
+
+package gc
+
+const raceEnabled = false
"cmd/internal/src"
"cmd/internal/sys"
"fmt"
+ "math/rand"
"sort"
"sync"
)
// and waits for them to complete.
func compileFunctions() {
if len(compilequeue) != 0 {
- // Compile the longest functions first,
- // since they're most likely to be the slowest.
- // This helps avoid stragglers.
- obj.SortSlice(compilequeue, func(i, j int) bool {
- return compilequeue[i].Nbody.Len() > compilequeue[j].Nbody.Len()
- })
+ if raceEnabled {
+ // Randomize compilation order to try to shake out races.
+ tmp := make([]*Node, len(compilequeue))
+ perm := rand.Perm(len(compilequeue))
+ for i, v := range perm {
+ tmp[v] = compilequeue[i]
+ }
+ copy(compilequeue, tmp)
+ } else {
+ // Compile the longest functions first,
+ // since they're most likely to be the slowest.
+ // This helps avoid stragglers.
+ obj.SortSlice(compilequeue, func(i, j int) bool {
+ return compilequeue[i].Nbody.Len() > compilequeue[j].Nbody.Len()
+ })
+ }
var wg sync.WaitGroup
c := make(chan *Node)
for i := 0; i < nBackendWorkers; i++ {
--- /dev/null
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build race
+
+package gc
+
+const raceEnabled = true