get-defined-fun: handle :declared-verify.
[sbcl.git] / tests / kill-non-lisp-thread.c
blob260573afa5e711800c505e498ebc6f2b704545d4
1 #include <unistd.h> // for sleep()
2 #include <stdio.h> // for perror()
3 #include <stdlib.h> // for exit()
4 #include <pthread.h>
5 #include <signal.h>
7 #ifdef __APPLE__
8 #include <dispatch/dispatch.h>
9 dispatch_semaphore_t sem, sem2;
10 #else
11 #include <semaphore.h>
12 sem_t sem, sem2;
13 #endif
15 void
16 wait_a_bit(void)
18 #ifdef __APPLE__
19 dispatch_semaphore_signal(sem);
20 dispatch_semaphore_wait(sem2, DISPATCH_TIME_FOREVER);
21 #else
22 sem_post(&sem);
23 sem_wait(&sem2);
24 #endif
27 void
28 kill_non_lisp_thread(void)
30 pthread_t kid;
32 #ifdef __APPLE__
33 if(!(sem = dispatch_semaphore_create(0)) ||
34 !(sem2 = dispatch_semaphore_create(0))) {
35 perror("dispatch_semaphore_create");
36 exit(1);
38 #else
39 if (sem_init(&sem, 0, 0) || sem_init(&sem2, 0, 0)) {
40 perror("sem_init");
41 exit(1);
43 #endif
45 if (pthread_create(&kid, 0, (void *(*)(void *))wait_a_bit, 0) < 0) {
46 perror("pthread_create");
47 exit(1);
50 #ifdef __APPLE__
51 dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
52 #else
53 sem_wait(&sem);
54 #endif
56 if (pthread_kill(kid, SIGURG)) {
57 perror("pthread_kill");
60 #ifdef __APPLE__
61 dispatch_semaphore_signal(sem2);
62 #else
63 sem_post(&sem2);
64 #endif