Fortran: Use OpenACC's acc_on_device builtin, fix OpenMP' __builtin_is_initial_device
[official-gcc.git] / libgo / go / os / exec / exec_linux_test.go
blob4a37c96e63a0ad66be60aff2e77a1a391a7c8f83
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.
13 // See issue 25628.
15 package exec_test
17 import (
18 "os"
19 "sync"
20 "syscall"
21 "time"
24 func init() {
25 if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" {
26 return
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.
33 const threads = 10
35 var wg sync.WaitGroup
36 wg.Add(threads)
37 ts := syscall.NsecToTimespec((100 * time.Microsecond).Nanoseconds())
38 for i := 0; i < threads; i++ {
39 go func() {
40 defer wg.Done()
41 syscall.Nanosleep(&ts, nil)
42 }()
44 wg.Wait()