This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Setting Signals to Inactive Threads

I have couple questions regarding setting signals to inactive threads using RTX and CMSIS. Please see the example code below:

osThreadId thread_id = osThreadCreate(osThread(thread_body), NULL); /* set thread active */

osThreadTerminate(thread_id); /* set thread inactive */

osSignalSet(thread_id, 1); /* set signal to inactive thread */

osThreadCreate(osThread(thread_body), NULL); /* set same thread active again */

void thread_body (void const * arg)
{ osSignalWait(1, 0); /* is the signal set? */
}

Questions:
1) The signal is set while the thread is inactive. What is the effect of this?
2) In the thread_body function, will the signal be set?

Thank you

Parents
  • That is considered erroneous code. Calling Terminate is very similar to calling free. You may still have a ThreadId pointer, but what it points to is no longer allocated to any thread so the data should be considered to have no meaning. The behavior is entirely undefined.

    Actual answers to the questions:

    1) Sets Signal for now terminated thread, does nothing as task is not waiting for signals Sets Signal for a thread that has the same threadId as the old Thread. Fails to Set anything for various reasons.

    2) No. Events are cleared on each Thread Creation. There are no cases that this will be set for a newly created thread.

Reply
  • That is considered erroneous code. Calling Terminate is very similar to calling free. You may still have a ThreadId pointer, but what it points to is no longer allocated to any thread so the data should be considered to have no meaning. The behavior is entirely undefined.

    Actual answers to the questions:

    1) Sets Signal for now terminated thread, does nothing as task is not waiting for signals Sets Signal for a thread that has the same threadId as the old Thread. Fails to Set anything for various reasons.

    2) No. Events are cleared on each Thread Creation. There are no cases that this will be set for a newly created thread.

Children