Discussion:
[nuttx] Posix timer in multi-thread
min.yang77@yahoo.com [nuttx]
2018-01-23 21:43:34 UTC
Permalink
Hello,


I implement a periodic posix timer with two threads. The setup is below.
In thread 1, I create a timer with a signal number and signal handler. I have a sem_wait function to test if a signal is received.
In thread 2, I have a sem_wait function just to test if a signal is received.
When running the program, I realized that when timer expires, the signal always goes to thread 1 and never goes to thread 2.
As my understand, signal's scope is based on task in nuttx, not a thread. So I expect thread 2 to receive signal as well. Could you please help explain this situation?


Thanks,
Min
spudarnia@yahoo.com [nuttx]
2018-01-23 21:54:01 UTC
Permalink
We need to be careful in understanding signal handling when we are talking about tasks and threads. Deliver of signals is a multi-threaded POSIX task is complex an non-intuitive.

Maybe this will help: http://www.nuttx.org/doku.php?id=wiki:nxinternal:tasksnthreads&#qhow_do_signals_work_in_a_task_group_with_many_pthreads

Does that address your issue?
spudarnia@yahoo.com [nuttx]
2018-01-23 21:57:27 UTC
Permalink
Strange as it is, I did not make this up. It is POSIX.

Your options are:

1. Use the sigprocmask to control which threads are eligible to receive signals, or
2. Use the pthread_kill() to signal specific threads.
min.yang77@yahoo.com [nuttx]
2018-01-24 00:17:50 UTC
Permalink
Thanks for your reply. Somehow my experience is different to the article that you provided. In multi-thread situation, I always received from the calling thread. But good to know that it should be indeterminate threads and I can use the methods that you mentioned to make sure I get the correct result.
Loading...