Skip to content

Commit

Permalink
rp2/mpthreadport: Ensure core1 doesn't hold gc lock in deinit.
Browse files Browse the repository at this point in the history
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 <jim.mussared@gmail.com>
  • Loading branch information
jimmo authored and dpgeorge committed Jun 30, 2022
1 parent b004e7e commit 797a83a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ports/rp2/mpthreadport.c
Expand Up @@ -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) {
Expand Down

0 comments on commit 797a83a

Please sign in to comment.