diff options
author | David Lechner <david@pybricks.com> | 2023-08-03 15:20:30 -0500 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2023-09-03 18:49:18 +1000 |
commit | ffb43b2dd37f10f48612d369b5cad9731c2a0597 (patch) | |
tree | cecc29542135b957063038985bdb466e3b05ddae /py/modthread.c | |
parent | c0d4c604e6a140c0f2967e1b43fd94d0b029c73f (diff) |
py/modthread: Return thread id from start_new_thread().
In CPython, `_thread.start_new_thread()` returns an ID that is the same ID
that is returned by `_thread.get_ident()`. The current MicroPython
implementation of `_thread.start_new_thread()` always returns `None`.
This modifies the required functions to return a value. The native thread
id is returned since this can be used for interop with other functions, for
example, `pthread_kill()` on *nix. `_thread.get_ident()` is also modified
to return the native thread id so that the values match and avoids the need
for a separate `native_id` attribute.
Fixes issue #12153.
Signed-off-by: David Lechner <david@pybricks.com>
Diffstat (limited to 'py/modthread.c')
-rw-r--r-- | py/modthread.c | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/py/modthread.c b/py/modthread.c index 51d63e470..6b7547490 100644 --- a/py/modthread.c +++ b/py/modthread.c @@ -129,7 +129,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( STATIC size_t thread_stack_size = 0; STATIC mp_obj_t mod_thread_get_ident(void) { - return mp_obj_new_int_from_uint((uintptr_t)mp_thread_get_state()); + return mp_obj_new_int_from_uint(mp_thread_get_id()); } STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_thread_get_ident_obj, mod_thread_get_ident); @@ -268,9 +268,7 @@ STATIC mp_obj_t mod_thread_start_new_thread(size_t n_args, const mp_obj_t *args) th_args->fun = args[0]; // spawn the thread! - mp_thread_create(thread_entry, th_args, &th_args->stack_size); - - return mp_const_none; + return mp_obj_new_int_from_uint(mp_thread_create(thread_entry, th_args, &th_args->stack_size)); } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_thread_start_new_thread_obj, 2, 3, mod_thread_start_new_thread); |