Closed lu-maca closed 3 months ago
Hi! It seems like there are several concepts involved here:
POSIX signal handling in cactus-rt is designed to allow your application to listen to a POSIX signal. The primary intended usage for this is for the application to gracefully shutdown upon receiving of a termination signal from outside the process. The signal_handling_example
shows how this can be done via either the wait on semaphore method or the busy wait method: https://github.com/cactusdynamics/cactus-rt/blob/0ee4132/examples/signal_handling_example/main.cc#L47-L55.
Waking a non-RT thread from a RT thread is not easily solvable by cactus-rt. It seems like this is what you want? There are in principle two solutions to this problem:
sem_*
and pthread_cond_*
are not real-time friendly due to the lack of priority inheritance support (for details see glibc bug 11588 and the 2020 talk of "librtpi: Conditional Variables for Real-Time Applications" by Gratian Crisan). In fact, upstream has no known solution to this problem.We have internally also discussed the second problem of waking a non-RT thread from a RT thread (and vice versa, or even RT-to-RT signaling). Our thought process on it is as follows:
These imply it will be difficult for us to create a generally-applicable interface for this in cactus-rt, which is supposed to generally support 1000Hz hard-real-time applications without too many gotchas. It's likely better, at this time, for applications to pick one of the above solutions and understand the tradeoff being made. In the future where more low-level libraries are available, we may revisit this stance.
Thanks for the exhaustive reply. Waking a thread from another is exactly what I would like.
Basically my problem is the following: I have two threads, the first RT that sends a pulse per second and the other that shall "receive" the PPS and after 75ms do some job. Then, this second thread shall do this job every 125ms until the PPS is sent again by the first thread; when this happens the second shall "realign" with it, wait again 75ms and do the job as previously.
My first idea was to raise a SIGUSR1/USR2 signal from the first thread and to catch it in the second thread.
That seems like an application-specific concerns and I don't think there's anything the framework can do. As a note, Linux signal handlers are meant not for generic code and has lots of restrictions. See signal-safety(7).
That seems like an application-specific concerns and I don't think there's anything the framework can do. As a note, Linux signal handlers are meant not for generic code and has lots of restrictions. See signal-safety(7).
Having a thread that wakes others is indeed a typical problem of real time systems. I'm trying to understand what are the limitations of using linux as a RTOS, this one is a big one.
Thanks for the infos.
Luca
Hi all,
let's say I have two threads, one RT and the other non RT and the latter shall wait for an event from the first. Are you planning to introduce a generic "signal handling" module in the framework? At the moment, as far as I can see, only some termination signals can be handled.
Thanks :) Luca