Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Program not exiting after using POSIX timers

Consider the following program:

#define _POSIX_C_SOURCE 200809L
#include <time.h>
#include <pthread.h>
#include <signal.h>

void timerfunc(union sigval val) { }

int main()
{
        struct sigevent sev = { .sigev_notify = SIGEV_THREAD,
                .sigev_notify_function = timerfunc };
        timer_t t;
        timer_create(CLOCK_REALTIME, &sev, &t);
        timer_delete(t);
        pthread_exit(0);
}

Linked with glibc, it not only fails to terminate, but it is unkillable except by kill -9/SIGKILL. Is this behavior permitted by the standard? Are there good workarounds aside from either always explicitly exiting the process (as opposed to just exiting all threads)?

like image 591
R.. GitHub STOP HELPING ICE Avatar asked Jun 11 '26 13:06

R.. GitHub STOP HELPING ICE


1 Answers

Well, POSIX specifically says it is

...impossible to determine the lifetime of the created thread...

which implies that any lifetime is allowed.

SIGEV_THREAD is simply bad mojo, and should be avoided.

like image 126
caf Avatar answered Jun 13 '26 01:06

caf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!