From 797a83ac3ef8f9bbf67faf59da665b5509db428b Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Wed, 29 Jun 2022 13:56:12 +1000 Subject: [PATCH] rp2/mpthreadport: Ensure core1 doesn't hold gc lock in deinit. Prior to this commit the following code would lock up the device when Ctrl-D is entered at the REPL: import gc, _thread def collect_thread(): while True: gc.collect() _thread.start_new_thread(collect_thread, []) Fixes part of #8494. Signed-off-by: Jim Mussared --- ports/rp2/mpthreadport.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ports/rp2/mpthreadport.c b/ports/rp2/mpthreadport.c index cdb5945d21..187f74bb57 100644 --- a/ports/rp2/mpthreadport.c +++ b/ports/rp2/mpthreadport.c @@ -47,8 +47,13 @@ void mp_thread_init(void) { } void mp_thread_deinit(void) { + assert(get_core_num() == 0); + // Must ensure that core1 is not currently holding the GC lock, otherwise + // it will be terminated while holding the lock. + mp_thread_mutex_lock(&MP_STATE_MEM(gc_mutex), 1); multicore_reset_core1(); core1_entry = NULL; + mp_thread_mutex_unlock(&MP_STATE_MEM(gc_mutex)); } void mp_thread_gc_others(void) {