I have configured a timer with timer_create() and timer_settime(). Also registered to notify the threads with a pulse when timeout occurs. My issue is, i have only one timer and i need timeout notification to be send to 2 threads. I have registered for notification using SIGEV_PULSE_INIT() with 2 connection IDs
Note that SIGEV_PULSE_INIT() is not a routine call, but is a macro that sets up data. So you are overwriting the data with the second line.
But that is not your real problem. A timer will only send one pulse. There are various ways around this.
I would suggest one very simple way around the problem.
Instead of setting the timer, create a thread that does the following:
For sleep() i would need a dedicated thread, right? To avoid one dedicated thread, i was thinking of such a design. If it does not work, its ok
Consider 2 options:
Option 1: Say i designed a thread and registered to get timer notification pulse. When timeout occurs, thread receives it sends pulse to 2 threads waiting for the timer pulse. So in this design there are altogether 3 threads and one timer.
Option 2: Create 2 timers (for same timeout values), and register to get notification(i.e one timer for one thread). Here, the number of threads is 2, but 2 timers with same timeout value
So which design would you suggest, the 1st or the 2nd.
I think both would work. I like the idea the of the first notified thread notifying the 2nd better, but I doubt there is much difference in the impact.