Skip to content

Commit e374cff

Browse files
committed
py/modthread: Raise RuntimeError in release() if lock is not acquired.
1 parent a47b871 commit e374cff

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

py/modthread.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(thread_lock_acquire_obj, 1, 3, thread
8484

8585
STATIC mp_obj_t thread_lock_release(mp_obj_t self_in) {
8686
mp_obj_thread_lock_t *self = MP_OBJ_TO_PTR(self_in);
87-
// TODO check if already unlocked
87+
if (!self->locked) {
88+
mp_raise_msg(&mp_type_RuntimeError, NULL);
89+
}
8890
self->locked = false;
8991
MP_THREAD_GIL_EXIT();
9092
mp_thread_mutex_unlock(&self->mutex);

tests/thread/thread_lock1.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,9 @@
3838
except KeyError:
3939
print('KeyError')
4040
print(lock.locked())
41+
42+
# test that we can't release an unlocked lock
43+
try:
44+
lock.release()
45+
except RuntimeError:
46+
print('RuntimeError')

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy