aboutsummaryrefslogtreecommitdiff
path: root/py/modthread.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-05-26 10:42:53 +0000
committerDamien George <damien.p.george@gmail.com>2016-06-28 11:28:50 +0100
commit4cec63a9dbed86c4332b9e7fcd56d092046193e4 (patch)
tree9e5e0636411f5de6647d4021c8069a39cb031f14 /py/modthread.c
parent1f54ad2aed0dc8f2d868ccd89ccf639a475e8022 (diff)
py: Implement a simple global interpreter lock.
This makes the VM/runtime thread safe, at the cost of not being able to run code in parallel.
Diffstat (limited to 'py/modthread.c')
-rw-r--r--py/modthread.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/py/modthread.c b/py/modthread.c
index 930ca45bb..7efad78c9 100644
--- a/py/modthread.c
+++ b/py/modthread.c
@@ -146,6 +146,8 @@ typedef struct _thread_entry_args_t {
} thread_entry_args_t;
STATIC void *thread_entry(void *args_in) {
+ // Execution begins here for a new thread. We do not have the GIL.
+
thread_entry_args_t *args = (thread_entry_args_t*)args_in;
mp_state_thread_t ts;
@@ -154,6 +156,8 @@ STATIC void *thread_entry(void *args_in) {
mp_stack_set_top(&ts + 1); // need to include ts in root-pointer scan
mp_stack_set_limit(16 * 1024); // fixed stack limit for now
+ MP_THREAD_GIL_ENTER();
+
// signal that we are set up and running
mp_thread_start();
@@ -188,6 +192,8 @@ STATIC void *thread_entry(void *args_in) {
// signal that we are finished
mp_thread_finish();
+ MP_THREAD_GIL_EXIT();
+
return NULL;
}