]> git.saurik.com Git - apple/libpthread.git/blob - tests/pthread_cancel.c
20b8f88e4bf0e3ace2a874144ac447458a4e21c4
[apple/libpthread.git] / tests / pthread_cancel.c
1 #include <pthread.h>
2
3 #include <darwintest.h>
4
5 static void *
6 run(void * __unused arg)
7 {
8 while (true) {
9 pthread_testcancel();
10 sched_yield();
11 }
12 }
13
14 T_DECL(pthread_cancel, "pthread_cancel",
15 T_META_ALL_VALID_ARCHS(YES))
16 {
17 pthread_t thread;
18 void *join_result = NULL;
19 T_ASSERT_POSIX_ZERO(pthread_create(&thread, NULL, run, NULL), NULL);
20 T_ASSERT_POSIX_ZERO(pthread_cancel(thread), NULL);
21 T_ASSERT_POSIX_ZERO(pthread_join(thread, &join_result), NULL);
22 T_ASSERT_EQ(join_result, PTHREAD_CANCELED, NULL);
23 }