diff options
author | Ian Moffett <ian@osmora.org> | 2024-03-07 17:28:00 -0500 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2024-03-07 17:28:32 -0500 |
commit | bd5969fc876a10b18613302db7087ef3c40f18e1 (patch) | |
tree | 7c2b8619afe902abf99570df2873fbdf40a4d1a1 /lib/mlibc/tests/posix/pthread_kill.c | |
parent | a95b38b1b92b172e6cc4e8e56a88a30cc65907b0 (diff) |
lib: Add mlibc
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'lib/mlibc/tests/posix/pthread_kill.c')
-rw-r--r-- | lib/mlibc/tests/posix/pthread_kill.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/mlibc/tests/posix/pthread_kill.c b/lib/mlibc/tests/posix/pthread_kill.c new file mode 100644 index 0000000..b740b70 --- /dev/null +++ b/lib/mlibc/tests/posix/pthread_kill.c @@ -0,0 +1,46 @@ +#include <assert.h> +#include <pthread.h> +#include <signal.h> + +_Atomic int handler_ready = 0; +_Atomic int thread_signal_ran = 0; + +static void sig_handler(int sig, siginfo_t *info, void *ctx) { + (void)sig; + (void)info; + (void)ctx; + + thread_signal_ran = 1; +} + +static void *worker(void *arg) { + (void)arg; + + struct sigaction sa; + sigemptyset(&sa.sa_mask); + sa.sa_sigaction = sig_handler; + sa.sa_flags = SA_SIGINFO; + assert(!sigaction(SIGUSR1, &sa, NULL)); + + handler_ready = 1; + + while (!thread_signal_ran) + ; + + return NULL; +} + +int main() { + pthread_t thread; + assert(!pthread_create(&thread, NULL, &worker, NULL)); + + while (!handler_ready) + ; + + assert(!pthread_kill(thread, SIGUSR1)); + assert(!pthread_join(thread, NULL)); + + assert(thread_signal_ran); + + return 0; +} |