Skip to content

Commit 1a5c8d1

Browse files
committed
py/vm: Don't release the GIL if the scheduler is locked.
The scheduler being locked general means we are running a scheduled function, and switching to another thread violates that, so don't switch in such a case (even though we technically could). And if we are running a scheduled function then we want to finish it ASAP, so we shouldn't switch to another thread. Furthermore, ports with threading enabled will lock the scheduler during a hard IRQ, and this patch to the VM will make sure that threads are not switched during a hard IRQ (which would crash the VM).
1 parent 231cfc8 commit 1a5c8d1

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

py/vm.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,8 +1301,14 @@ unwind_jump:;
13011301
#else
13021302
{
13031303
#endif
1304+
#if MICROPY_ENABLE_SCHEDULER
1305+
// can only switch threads if the scheduler is unlocked
1306+
if (MP_STATE_VM(sched_state) == MP_SCHED_IDLE)
1307+
#endif
1308+
{
13041309
MP_THREAD_GIL_EXIT();
13051310
MP_THREAD_GIL_ENTER();
1311+
}
13061312
}
13071313
#endif
13081314

0 commit comments

Comments
 (0)