py/scheduler: Add assert that scheduler is locked when unlocking.

And add a test that shows how this can happen when multiple threads are
accessing the scheduler, which fails if atomic sections are not used.
This commit is contained in:
Jim Mussared
2020-04-03 13:16:28 +11:00
committed by Damien George
parent 243805d776
commit 8470cd0be9
3 changed files with 51 additions and 0 deletions

View File

@@ -108,6 +108,7 @@ void mp_sched_lock(void) {
void mp_sched_unlock(void) {
mp_uint_t atomic_state = MICROPY_BEGIN_ATOMIC_SECTION();
assert(MP_STATE_VM(sched_state) < 0);
if (++MP_STATE_VM(sched_state) == 0) {
// vm became unlocked
if (MP_STATE_VM(mp_pending_exception) != MP_OBJ_NULL || mp_sched_num_pending()) {