3 #include "darwintest_defaults.h"
5 static volatile int once_invoked
= 0;
8 cancelation_handler(void * __unused arg
)
13 __attribute__((noreturn
))
15 await_cancelation(void)
17 pthread_cleanup_push(cancelation_handler
, NULL
);
18 T_LOG("waiting for cancellation");
20 // can't use darwintest once cancellation is enabled
21 pthread_setcancelstate(PTHREAD_CANCEL_ENABLE
, NULL
);
28 pthread_cleanup_pop(0);
32 await_cancelation_in_once(void *arg
)
34 // disable cancellation until pthread_once to protect darwintest
35 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE
, NULL
);
37 T_LOG("starting the thread");
38 pthread_once_t
*once
= (pthread_once_t
*)arg
;
39 pthread_once(once
, await_cancelation
);
46 T_LOG("once invoked");
50 T_DECL(once_cancel
, "pthread_once is re-executed if cancelled")
52 pthread_once_t once
= PTHREAD_ONCE_INIT
;
54 void *join_result
= NULL
;
57 pthread_create(&t
, NULL
, await_cancelation_in_once
, &once
), NULL
);
58 T_ASSERT_POSIX_ZERO(pthread_cancel(t
), NULL
);
59 T_ASSERT_POSIX_ZERO(pthread_join(t
, &join_result
), NULL
);
60 T_ASSERT_EQ(join_result
, PTHREAD_CANCELED
, NULL
);
62 T_ASSERT_POSIX_ZERO(pthread_once(&once
, oncef
), NULL
);
63 T_ASSERT_EQ(once_invoked
, 1, NULL
);