xref: /openbsd-src/regress/sys/kern/signal/sigpthread/README (revision 6bcfccda660a0ea1c51395cf0b89694d927c87dd)
1*6bcfccdaSmpiTest the interaction of signals with multiple posix threads.
2*6bcfccdaSmpi
3*6bcfccdaSmpiSignal SIGUSR1 is used for thread coordination, SIGUSR2 to test
4*6bcfccdaSmpisignal delivery.  First SIGUSR1 and SIGUSR2 get blocked.  Then a
5*6bcfccdaSmpigiven number of threads are created, the main thread is also counted
6*6bcfccdaSmpias a thread.
7*6bcfccdaSmpi
8*6bcfccdaSmpiSignal SIGUSR2 is send to the process with kill(2), but it is not
9*6bcfccdaSmpidelivered yet as it is blocked in all threads.  Meanwhile the threads
10*6bcfccdaSmpiwait for SIGUSR1 in sigsuspend(2).  This enforces that SIGUSR2 is
11*6bcfccdaSmpimarked as pending at the process.  To continue, SIGUSR1 is sent to
12*6bcfccdaSmpiall threads and they wake up.  Only one thread is configured to
13*6bcfccdaSmpihandle SIGUSR2, this one unblocks it with pthread_sigmask(3).  The
14*6bcfccdaSmpisignal should be delivered immediately, the handler records it.
15*6bcfccdaSmpi
16*6bcfccdaSmpiThe test is considered successful if the thread that unblocks SIGUSR2
17*6bcfccdaSmpiactually handles it.
18*6bcfccdaSmpi
19*6bcfccdaSmpiTo test different race conditions, sleeps can be inserted.  If the
20*6bcfccdaSmpikill(2) is delayed, SIGUSR2 hits the threads when they are in
21*6bcfccdaSmpisigsuspend(2).  If the sleep is before sigsuspend(2), the threads
22*6bcfccdaSmpiare in nanosleep(2).  The unblocking pthread_sigmask(3) can be
23*6bcfccdaSmpidelayed so that the other threads have been joined already.
24*6bcfccdaSmpi
25*6bcfccdaSmpiIt is also possible to avoid blocking the signals and check which
26*6bcfccdaSmpihandler catches it.  Alternatively sigwait(3) can be used to test
27*6bcfccdaSmpisignal reception.
28