mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-11 07:02:29 +00:00
Demonstrate signal safety of recursive mutexes
This commit is contained in:
parent
135d538b1d
commit
fdab49b30e
2 changed files with 112 additions and 0 deletions
30
test/posix/exit_async_signal_safety_test.c
Normal file
30
test/posix/exit_async_signal_safety_test.c
Normal file
|
@ -0,0 +1,30 @@
|
|||
#include <pthread.h>
|
||||
#include <stdatomic.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
atomic_bool ready;
|
||||
|
||||
void* work(void* arg) {
|
||||
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0);
|
||||
ready = true;
|
||||
pthread_exit(0);
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
for (int i = 0; i < 1000; ++i) {
|
||||
pthread_t th;
|
||||
if (pthread_create(&th, 0, work, 0))
|
||||
_Exit(1);
|
||||
for (;;)
|
||||
if (ready)
|
||||
break;
|
||||
pthread_cancel(th);
|
||||
if (pthread_join(th, 0))
|
||||
_Exit(3);
|
||||
}
|
||||
|
||||
while (!pthread_orphan_np())
|
||||
pthread_decimate_np();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue