github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/runtime/sigqueue.go (about) 1 // Copyright 2009 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. 4 5 // This file implements runtime support for signal handling. 6 // 7 // Most synchronization primitives are not available from 8 // the signal handler (it cannot block, allocate memory, or use locks) 9 // so the handler communicates with a processing goroutine 10 // via struct sig, below. 11 // 12 // sigsend is called by the signal handler to queue a new signal. 13 // signal_recv is called by the Go program to receive a newly queued signal. 14 // 15 // Synchronization between sigsend and signal_recv is based on the sig.state 16 // variable. It can be in three states: 17 // * sigReceiving means that signal_recv is blocked on sig.Note and there are 18 // no new pending signals. 19 // * sigSending means that sig.mask *may* contain new pending signals, 20 // signal_recv can't be blocked in this state. 21 // * sigIdle means that there are no new pending signals and signal_recv is not 22 // blocked. 23 // 24 // Transitions between states are done atomically with CAS. 25 // 26 // When signal_recv is unblocked, it resets sig.Note and rechecks sig.mask. 27 // If several sigsends and signal_recv execute concurrently, it can lead to 28 // unnecessary rechecks of sig.mask, but it cannot lead to missed signals 29 // nor deadlocks. 30 31 //go:build !plan9 32 33 package runtime