We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Passing thread-IDs via global variables is nothing ugly unless these are "constant".In your case, since threads are created on start-up the thread-id won't change later on.Regarding your problem, the simplest thing is to activate the interrupt from within the foreground thread.So it is sure the global thread-id is valid.
I guess uglyness is in the eye of the beholder but I prefer to avoid global data where at all possible.However you are wrong to say that my threads are created at start-up and, in addition, the objects which access the hardware need to be deleted and created dynamically in my application so some form of INVALID_THREAD_ID token is required by my software.
if (tsk == 0) { // Invalid task ID sysThreadError(osErrorNoMemory); // Create task failed (Out of memory) return NULL; }
Didn't know RTX allows to create dynamic processes.
osThreadId osThreadCreate (osThreadDef_t *thread_def, void *argument) Create a thread and add it to Active Threads and set it to state READY. osThreadId osThreadGetId (void) Return the thread ID of the current running thread. osStatus osThreadTerminate (osThreadId thread_id) Terminate execution of a thread and remove it from Active Threads. osThreadId osThreadCreate (osThreadDef_t *thread_def, void *argument) Create a thread and add it to Active Threads and set it to state READY. osThreadId osThreadGetId (void) Return the thread ID of the current running thread. osStatus osThreadTerminate (osThreadId thread_id) Terminate execution of a thread and remove it from Active Threads. osThreadId osThreadCreate (osThreadDef_t *thread_def, void *argument) Create a thread and add it to Active Threads and set it to state READY. osThreadId osThreadGetId (void) Return the thread ID of the current running thread. osStatus osThreadTerminate (osThreadId thread_id) Terminate execution of a thread and remove it from Active Threads.
Anyway, the cleanest way would be to send a message to the interrupt process to tell it the thread id.And of course, if the receiver gets killed, also notify the interrupt thread about that so it will discard the thread id.
BTW found this in the RTX sources:...snip..So it is perfect clear the NULL is an ivalid thread ID esp. because it is a pointer.