QXK: Extended thread context switch causes assertion in PendSV_Handler
Real-Time Event Frameworks based on active objects & state machines
Brought to you by:
quantum-leaps
The following scenario causes assertion in PendSV_Handler in the QXK kernel (QP/C/C++ 5.9.9):
QXSemaphore_wait() with count = 0 (i.e. thread 18 should block).QXSemaphore_wait() calls QXK_sched_() inside a critical regionQXK_sched_() finds extended thread or Active Object with priority = 17 ready, sets the next pointer to it, and triggers a context switch (i.e. PendSV is set)QXSemaphore_wait().QXSemaphore_wait() re-enables interrupts, this ISR will immediately executes (since it is higher priority than PendSV) and suppose it makes the same extended thread with priority=18 ready again; NOTE: QXSemaphore_signal() does not context switch since we are inside ISR.QXK_ISR_EXIT(), this in turn calls QXK_sched_().QXK_sched_() sees that the curr active thread #18 is the same as the next active thread #18 and sets QXK_attr_.next pointer to 0.QXK_sched_(). However this time the next pointer is 0 and PendSV will trigger an assert failure (at label PendSV_error).--MMS
Anonymous
This bug will be fixed in the upcoming QP/C/C++ 6.0.0 by modifying
QXK_sched_()as follows:old code:
new code:
This will ensure that the
QXK_attr_.nextpointer has the non-NULL value, so thePendSV_Handlerwill no longer assert. In this corner-case the current thread and the next thread will be the same, soPendSV_Handlerwill end up switching the context back and forth to the same extended thread. This has been tested to be safe.--MMS
Fixed in QP/C/C++6.0.0.
--MMS