Search code examples
csignalsposix

Run a signal handler without issuing a signal


Is there a mechanism where I can run a signal handler in another thread without invoking a signal?

I want to send a notification to a different thread and I was wondering if it can be done by interrupting its execution and make it run a callback while the thread is paused.

If there is no standard way to do it in POSIX, A Linux feature will also be useful. Also, if this feature exists, how would I block "signals" in the receiving thread?


Solution

  • Is there a mechanism where I can run a signal handler in another thread without invoking a signal?

    There is a variety of ways for one thread to request specific work from another. Signals are only one. HOWEVER, ...

    I want to send a notification to a different thread and I was wondering if it can be done by interrupting its execution and make it run a callback while the thread is paused.

    ... there is no way for a userspace thread to preempt another thread to make it perform work outside its normal flow of execution. Only the kernel can do that, and the mechanism for it is signal delivery. (One thread can request that a signal be delivered to another, so I'm drawing a somewhat fine distinction here, but the kernel needs to accept the request and to perform the actual signal delivery.)

    If there is no standard way to do it in POSIX, A Linux feature will also be useful.

    To the best of my knowledge, there is no Linux-specific feature available for this, either.