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>
This commit is contained in:
David Lechner
2023-08-03 15:20:30 -05:00
committed by Damien George
parent c0d4c604e6
commit ffb43b2dd3
9 changed files with 58 additions and 16 deletions

View File

@@ -54,7 +54,11 @@ void mp_thread_gc_others(void) {
mp_thread_mutex_unlock(&thread_mutex);
}
void mp_thread_create(void *(*entry)(void *), void *arg, size_t *stack_size) {
mp_uint_t mp_thread_get_id(void) {
return (uint32_t)pyb_thread_cur;
}
mp_uint_t mp_thread_create(void *(*entry)(void *), void *arg, size_t *stack_size) {
if (*stack_size == 0) {
*stack_size = 4096; // default stack size
} else if (*stack_size < 2048) {
@@ -82,6 +86,8 @@ void mp_thread_create(void *(*entry)(void *), void *arg, size_t *stack_size) {
// adjust stack_size to provide room to recover from hitting the limit
*stack_size -= 1024;
return id;
}
void mp_thread_start(void) {