Commit Graph

7 Commits

Author SHA1 Message Date
David Lechner ffb43b2dd3 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>
2023-09-03 18:49:18 +10:00
Damien George b1229efbd1 all: Fix spelling mistakes based on codespell check.
Signed-off-by: Damien George <damien@micropython.org>
2023-04-27 18:03:06 +10:00
Jim Mussared 662dc8602b rp2: Make atomic sections suspend the other core (if active).
When a flash write/erase is in progress, we need to ensure that the
other core cannot be using XIP.

This also implements MICROPY_BEGIN_ATOMIC_SECTION as a full mutex, which
is necessary as it's used to syncronise access to things like the scheduler
queue.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-07-12 16:20:21 +10:00
Jim Mussared 797a83ac3e rp2/mpthreadport: Ensure core1 doesn't hold gc lock in deinit.
Prior to this commit the following code would lock up the device when
Ctrl-D is entered at the REPL:

    import gc, _thread

    def collect_thread():
        while True:
            gc.collect()

    _thread.start_new_thread(collect_thread, [])

Fixes part of #8494.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-06-30 11:53:25 +10:00
YoungJoon Chun 2d47020e15 rp2/mpthreadport: Fix memory corruption when thread is created in core1.
The stack (and arg) of core1 is itself a root pointer, not just the entries
in it.  Without this fix the GC could reclaim the entire stack (and
argument object).

Fixes issues #7124 and #7981.
2022-03-01 17:03:57 +11:00
Damien George d0de16266f rp2/mpthreadport: Add mp_thread_deinit to reset core1 on soft reset.
Any code running on core1 should be stopped on soft-reset (the GC heap is
reset so if code continues to run on core1 it will see corrupt memory).

Signed-off-by: Damien George <damien@micropython.org>
2021-05-09 00:08:30 +10:00
Damien George 469345e728 rp2: Add new port to Raspberry Pi RP2 microcontroller.
This commit adds a new port "rp2" which targets the new Raspberry Pi RP2040
microcontroller.

The build system uses pure cmake (with a small Makefile wrapper for
convenience).  The USB driver is TinyUSB, and there is a machine module
with most of the standard classes implemented.  Some examples are provided
in the examples/rp2/ directory.

Work done in collaboration with Graham Sanderson.

Signed-off-by: Damien George <damien@micropython.org>
2021-01-30 00:42:29 +11:00