1 // Copyright 2020 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 //go:build linux && cgo
7 // On systems that use glibc, calling malloc can create a new arena,
8 // and creating a new arena can read /sys/devices/system/cpu/online.
9 // If we are using cgo, we will call malloc when creating a new thread.
10 // That can break TestExtraFiles if we create a new thread that creates
11 // a new arena and opens the /sys file while we are checking for open
12 // file descriptors. Work around the problem by creating threads up front.
25 if os
.Getenv("GO_WANT_HELPER_PROCESS") != "1" {
29 // Start some threads. 10 is arbitrary but intended to be enough
30 // to ensure that the code won't have to create any threads itself.
31 // In particular this should be more than the number of threads
32 // the garbage collector might create.
37 ts
:= syscall
.NsecToTimespec((100 * time
.Microsecond
).Nanoseconds())
38 for i
:= 0; i
< threads
; i
++ {
41 syscall
.Nanosleep(&ts
, nil)