forked from dtrace4linux/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththread.c
More file actions
35 lines (31 loc) · 933 Bytes
/
thread.c
File metadata and controls
35 lines (31 loc) · 933 Bytes
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
/* Simple thread test - am having problems proving dtrace
thread/posix locking works; could be a vmware issue... */
# include <stdio.h>
# include <pthread.h>
# include <signal.h>
pthread_mutex_t m;
static void
thread(void *arg)
{
printf("2: in thread...about to lock\n");
pthread_mutex_lock(&m);
printf("2: in thread .. succeeded lock\n");
pause();
}
int main(int argc, char **argv)
{ pthread_t tid;
pthread_attr_t a;
sigset_t nset, oset;
pthread_mutex_init(&m, NULL);
printf("1: main creating thread\n");
pthread_mutex_lock(&m);
(void) pthread_attr_init(&a);
(void) pthread_attr_setdetachstate(&a, PTHREAD_CREATE_DETACHED);
(void) sigfillset(&nset);
(void) sigdelset(&nset, SIGABRT); /* unblocked for assert() */
(void) sigdelset(&nset, SIGUSR1); /* see dt_proc_destroy() */
(void) pthread_sigmask(SIG_SETMASK, &nset, &oset);
pthread_create(&tid, NULL, thread, NULL);
printf("1: thread created\n");
pause();
}