aboutsummaryrefslogtreecommitdiff
path: root/py/scheduler.c
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2020-04-03 13:16:28 +1100
committerDamien George <damien.p.george@gmail.com>2020-04-13 21:55:47 +1000
commit8470cd0be90de03ba38103db69d134c8915bc114 (patch)
tree8568e6f470ed38a548f6ddefb0f3228e6519c980 /py/scheduler.c
parent243805d776a19b16545d542b2f51ae88b6e314fe (diff)
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.
Diffstat (limited to 'py/scheduler.c')
-rw-r--r--py/scheduler.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/py/scheduler.c b/py/scheduler.c
index d4d797508..b559091b8 100644
--- a/py/scheduler.c
+++ b/py/scheduler.c
@@ -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()) {