diff --git a/ports/esp32/mpthreadport.c b/ports/esp32/mpthreadport.c index 140a76464f..bbfc53d3f5 100644 --- a/ports/esp32/mpthreadport.c +++ b/ports/esp32/mpthreadport.c @@ -166,6 +166,8 @@ void mp_thread_finish(void) { mp_thread_mutex_unlock(&thread_mutex); } +// This is called from the FreeRTOS idle task and is not within Python context, +// so MP_STATE_THREAD is not valid and it does not have the GIL. void vPortCleanUpTCB(void *tcb) { if (thread == NULL) { // threading not yet initialised @@ -182,8 +184,7 @@ void vPortCleanUpTCB(void *tcb) { // move the start pointer thread = th->next; } - // explicitly release all its memory - m_del(thread_t, th, 1); + // The "th" memory will eventually be reclaimed by the GC. break; } }