CMSIS_5: osRtxThreadListPut hangs when the thread is already on the list
My application hangs occasionally in this kernel function. Examination of the arguments in a debugger shows that when the second argument (the thread) is already on the list represented by the first argument. In this situation the function never returns, and the RTX kernel becomes hung.
/// Put a Thread into specified Object list sorted by Priority (Highest at Head).
/// \param[in] object generic object.
/// \param[in] thread thread object.
void osRtxThreadListPut (volatile os_object_t *object, os_thread_t *thread) {
os_thread_t *prev, *next;
int32_t priority;
if (thread == NULL) {
return;
}
priority = thread->priority;
prev = (os_thread_t *)(uint32_t)object;
next = object->thread_list;
while ((next != NULL) && (next->priority >= priority)) {
prev = next;
next = next->thread_next;
}
thread->thread_prev = prev;
thread->thread_next = next;
prev->thread_next = thread;
if (next != NULL) {
next->thread_prev = thread;
}
}
In this case, the loop never exits because the next
pointer is always non-NULL
and the priority of the thread is always equal to the priority of the item in the list (since they’re actually the same object). I’ve seen this occur while managing the round-robin thread list and also while having a thread wait for EventFlags.
osRtxThreadListPut
already tries to be somewhat defensive by returning early when the passed thread is NULL
. It should gracefully handle the case where the thread is already on the list.
Perhaps these application hangs are due to some other misconfiguration on my part, but whatever the root cause, tracking down the fix is more difficult because the kernel itself hangs.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 24 (5 by maintainers)
At the moment, I’m only able to reproduce it inside the application I’m working on, but if I can reduce it to a smaller example, I’ll definitely share that.