Demonstrate signal safety of recursive mutexes

This commit is contained in:
Justine Tunney 2024-07-04 02:46:54 -07:00
parent 135d538b1d
commit fdab49b30e
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
2 changed files with 112 additions and 0 deletions

View 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();
}