View topic - Doubt in SIGEV_PULSE_INIT()

Page 1 of 1

Doubt in SIGEV_PULSE_INIT()

PostPosted: Thu Jan 31, 2013 4:26 am
by hello
Hi all,

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
SIGEV_PULSE_INIT(&t_timer_event,chid1,SIGEV_PULSE_PRIO_INHERIT,TIMER_PULSE,0);
SIGEV_PULSE_INIT(&t_timer_event,chid2,SIGEV_PULSE_PRIO_INHERIT,TIMER_PULSE,0);

But i am receiving the pulse only in one channel. Is this the expected behavior? Is it possible to receive pulse in 2 channels.

Regards,
hello

Re: Doubt in SIGEV_PULSE_INIT()

PostPosted: Thu Jan 31, 2013 7:17 am
by maschoen
Yes, this is the expected behavior.

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:
1) sleep for the required amount of time
2) send pulse 1
3) send pulse 2
3) exit the thread

Re: Doubt in SIGEV_PULSE_INIT()

PostPosted: Thu Jan 31, 2013 7:54 am
by hello
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.

Regards,
hello

Re: Doubt in SIGEV_PULSE_INIT()

PostPosted: Thu Jan 31, 2013 1:11 pm
by maschoen
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.

Re: Doubt in SIGEV_PULSE_INIT()

PostPosted: Thu Jan 31, 2013 1:42 pm
by hello
So increasing the number of timer is more good than creating an additional thread, right ?.
Ok thank you for your opinion

Regards,
hello

Re: Doubt in SIGEV_PULSE_INIT()

PostPosted: Thu Jan 31, 2013 4:57 pm
by maschoen
I don't think it makes much difference. It probably takes more resources to make a thread, but not much.