Having trouble tracking down answer to usage of SIGEV_THREAD...
When one sets SIGEV_THREAD as the notify method in sigevent struct, is it correct to assume that async-signal-safe functions must still be used within the notify_function to be invoked as the handler?
Also - is it correct to assume the thread is run as "detached"?
For example
notify thread
void my_thread(union sigval my_data)
{
// is this ok or not (two non async-signal-safe functions)?
printf("in the notify function\n");
mq_send();
}
main function
(...)
se.sigev_notify = SIGEV_THREAD;
se.sigev_value.sival_ptr = &my_data;
se.sigev_notify_function = my_thread;
se.sigev_notify_attributes = NULL;
(...)
Please provide a reference if possible.
No, you don't need to use only async-signal-safe functions, because POSIX does not place any such limitation on the
SIGEV_THREAD
function. (The whole point ofSIGEV_THREAD
is that it lets you handle asychronous notifications in a less constrained environment than a signal handler).As far as the thread being detached, POSIX says:
This means: you must either leave
sigev_notify_attributes
asNULL
, or set it to an attributes structure with the detachstate set toPTHREAD_CREATE_DETACHED
- in both cases the thread will be created detached.