I'm working with ChibiOS 20.3
I have static thread based on chibios_rt::BaseStaticThread.
Code in this thread checks for chThdShouldTerminateX() on each iteration.
If chThdShouldTerminateX() == true it calls chThdExit((msg_t)0x0).
Now I want to stop this thread, apply new config and start it again.
I have chibios_rt::ThreadReference ref for this thread.
So I'm doing:
Code: Select all
/* Getting a reference.*/
ref.addRef();
/* Asking for thread termination.*/
ref.requestTerminate();
/* Waiting for termination, releasing the reference.*/
ref.wait();
After this I see this thread in FINAL state:
Code: Select all
14 Thread 536891672 "MAX3185X" (Name: MAX3185X, State: FINAL) 0x080072b6 in chSchGoSleepS (newstate=<optimized out>) at ChibiOS/os/rt/src/chschd.c:235
Looks ok so far.
But when I try to start this thread again chThdCreateStatic fails on following assertion:
Code: Select all
#if (CH_CFG_USE_REGISTRY == TRUE) && \
((CH_DBG_ENABLE_STACK_CHECK == TRUE) || (CH_CFG_USE_DYNAMIC == TRUE))
chDbgAssert(chRegFindThreadByWorkingArea(wsp) == NULL,
"working area in use");
#endif
This is because thread is still in list. Comment to chRegFindThreadByWorkingArea function says:
Confirms that a working area is being used by some active thread.
Is thread with CH_STATE_FINAL state also considered active?
Am I missing some step after killing thread to remove it from registry?
If I just comment this assert in chThdCreateStatic then thread seems starts fine, but registry is corrupted, at least GDB shows only one task:
Code: Select all
(gdb) info thread
Id Target Id Frame
* 16 Thread 1 "Current Execution" (Name: Current Execution, No RTOS thread) Vector108 () at ChibiOS/os/hal/ports/STM32/LLD/TIMv1/hal_pwm_lld.c:310
Am I missing something trivial?