// ppc64 (issue #8912)
t.Skipf("no external linking on ppc64")
}
- got := runTestProg(t, "testprogcgo", "CgoExternalThreadSIGPROF")
- want := "OK\n"
- if got != want {
+
+ exe, err := buildTestProg(t, "testprogcgo", "-tags=threadprof")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ got, err := testEnv(exec.Command(exe, "CgoExternalThreadSIGPROF")).CombinedOutput()
+ if err != nil {
+ t.Fatalf("exit status: %v\n%s", err, got)
+ }
+
+ if want := "OK\n"; string(got) != want {
t.Fatalf("expected %q, but got:\n%s", want, got)
}
}
case "plan9", "windows":
t.Skipf("no pthreads on %s", runtime.GOOS)
}
- got := runTestProg(t, "testprogcgo", "CgoExternalThreadSignal")
- want := "OK\n"
- if got != want {
+
+ exe, err := buildTestProg(t, "testprogcgo", "-tags=threadprof")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ got, err := testEnv(exec.Command(exe, "CgoExternalThreadSIGPROF")).CombinedOutput()
+ if err != nil {
+ t.Fatalf("exit status: %v\n%s", err, got)
+ }
+
+ want := []byte("OK\n")
+ if !bytes.Equal(got, want) {
t.Fatalf("expected %q, but got:\n%s", want, got)
}
}
int getCPUHogThreadCount() {
return __sync_add_and_fetch(&cpuHogThreadCount, 0);
}
+
+static void* cpuHogDriver(void* arg __attribute__ ((unused))) {
+ while (1) {
+ cpuHogThread();
+ }
+ return 0;
+}
+
+void runCPUHogThread() {
+ pthread_t tid;
+ pthread_create(&tid, 0, cpuHogDriver, 0);
+}
*/
import "C"
os.Exit(2)
}
+ C.runCPUHogThread()
+
t0 := time.Now()
for C.getCPUHogThreadCount() < 2 && time.Since(t0) < time.Second {
time.Sleep(100 * time.Millisecond)
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
+// We only build this file with the tag "threadprof", since it starts
+// a thread running a busy loop at constructor time.
+
// +build !plan9,!windows
+// +build threadprof
package main
spinlock = 0;
return NULL;
}
+
__attribute__((constructor)) void issue9456() {
pthread_t tid;
pthread_create(&tid, 0, thread1, NULL);