View topic - Doubt in SIGEV_PULSE_INIT()
Doubt in SIGEV_PULSE_INIT()
6 posts
• Page 1 of 1
Doubt in SIGEV_PULSE_INIT()
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
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
- hello
- Senior Member
- Posts: 101
- Joined: Tue May 08, 2012 1:09 pm
Re: Doubt in SIGEV_PULSE_INIT()
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
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
- maschoen
- QNX Master
- Posts: 2728
- Joined: Wed Jun 25, 2003 5:18 pm
Re: Doubt in SIGEV_PULSE_INIT()
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
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
- hello
- Senior Member
- Posts: 101
- Joined: Tue May 08, 2012 1:09 pm
Re: Doubt in SIGEV_PULSE_INIT()
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.
- maschoen
- QNX Master
- Posts: 2728
- Joined: Wed Jun 25, 2003 5:18 pm
Re: Doubt in SIGEV_PULSE_INIT()
So increasing the number of timer is more good than creating an additional thread, right ?.
Ok thank you for your opinion
Regards,
hello
Ok thank you for your opinion
Regards,
hello
- hello
- Senior Member
- Posts: 101
- Joined: Tue May 08, 2012 1:09 pm
Re: Doubt in SIGEV_PULSE_INIT()
I don't think it makes much difference. It probably takes more resources to make a thread, but not much.
- maschoen
- QNX Master
- Posts: 2728
- Joined: Wed Jun 25, 2003 5:18 pm
6 posts
• Page 1 of 1
Who is online
Users browsing this forum: Google [Bot] and 6 guests