看著這個代碼的目的是只注冊一次sighandler,但是這個判定是否可以保證一次?但是根據代碼看,其實不會有關鍵區的讀寫,所以即使有同步問題,也不會產生什么特別的影響。所以代碼沒有問題,但是這是一個坑。
int
__pthread_cancel (pthread_t th)
{volatile struct pthread *pd = (volatile struct pthread *) th;if (pd->tid == 0)/* The thread has already exited on the kernel side. Its outcome(regular exit, other cancelation) has already beendetermined. */return 0;static int init_sigcancel = 0;if (atomic_load_relaxed (&init_sigcancel) == 0){struct sigaction sa;sa.sa_sigaction = sigcancel_handler;/* The signal handle should be non-interruptible to avoid the risk ofspurious EINTR caused by SIGCANCEL sent to process or ifpthread_cancel() is called while cancellation is disabled in thetarget thread. */sa.sa_flags = SA_SIGINFO | SA_RESTART;__sigemptyset (&sa.sa_mask);__libc_sigaction (SIGCANCEL, &sa, NULL);atomic_store_relaxed (&init_sigcancel, 1);}