blob: b5cd76f875e0d892de6b010674bf98139d1b496c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
/* $OpenBSD: sigdeliver.c,v 1.1 2002/10/12 03:39:21 marc Exp $ */
/* PUBLIC DOMAIN Oct 2002 <marc@snafu.org> */
/*
* test signal delivery of pending signals
*/
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include "test.h"
static pthread_mutex_t sync_mutex;
volatile sig_atomic_t got_signal;
/*
* sigusr1 signal handler.
*/
static void
sighandler(int signo)
{
got_signal += 1;
}
/*
* Install a signal handler for sigusr1 and then wait for it to
* occur.
*/
static void *
do_nothing (void *arg)
{
SET_NAME("nothing");
ASSERT(signal(SIGUSR1, sighandler) != SIG_ERR);
CHECKr(pthread_mutex_lock(&sync_mutex));
ASSERT(got_signal != 0);
CHECKr(pthread_mutex_unlock(&sync_mutex));
return 0;
}
int
main (int argc, char *argv[])
{
pthread_t pthread;
/* Initialize and lock a mutex. */
CHECKr(pthread_mutex_init(&sync_mutex, NULL));
CHECKr(pthread_mutex_lock(&sync_mutex));
/* start a thread that will wait on the mutex we now own */
CHECKr(pthread_create(&pthread, NULL, do_nothing, NULL));
/*
* Give the thread time to run and install its signal handler.
* The thread should be blocked waiting for the mutex we own.
* Give it a signal and then release the mutex and see if the
* signal is ever processed.
*/
sleep(2);
CHECKr(pthread_kill(pthread, SIGUSR1));
CHECKr(pthread_mutex_unlock(&sync_mutex));
CHECKr(pthread_join(pthread, NULL));
SUCCEED;
}
|