1 // Copyright 2017 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.
7 // This program hung when run under the C/C++ ThreadSanitizer. TSAN defers
8 // asynchronous signals until the signaled thread calls into libc. The runtime's
9 // sysmon goroutine idles itself using direct usleep syscalls, so it could
10 // run for an arbitrarily long time without triggering the libc interceptors.
11 // See https://golang.org/issue/18717.
20 #cgo CFLAGS: -g -fsanitize=thread
21 #cgo LDFLAGS: -g -fsanitize=thread
28 static void raise_usr2(int signo) {
32 static void register_handler(int signo) {
34 memset(&sa, 0, sizeof(sa));
35 sigemptyset(&sa.sa_mask);
36 sa.sa_flags = SA_ONSTACK;
37 sa.sa_handler = raise_usr2;
39 if (sigaction(SIGUSR1, &sa, NULL) != 0) {
40 perror("failed to register SIGUSR1 handler");
48 ch := make(chan os.Signal, 1)
49 signal.Notify(ch, syscall.SIGUSR2)
51 C.register_handler(C.int(syscall.SIGUSR1))
52 syscall.Kill(syscall.Getpid(), syscall.SIGUSR1)