QUERY · ISSUE
esp8266: multi threading
enhancementport-esp8266
Is it possible to build MicroPython for esp8266 with _thread support and how?
CANDIDATE · PULL REQUEST
Multi-threading support: core, unix and cc3200
This PR adds multi-threading support to MicroPython in the form of the _thread module. The work has been generously sponsored by Pycom (https://www.pycom.io). The parts that make this up are:
- core: separating out the thread specific state from
mp_state_ctxinto an individual structure, accessed viaMP_STATE_THREAD - core: the NLR pointer is now per-thread (for x86, x86-64 and thumb archs only)
- core: thread-safe garbage collector (using a global mutex)
- core: thread-safe qstrs (using a global mutex)
- core: addition of py/mpthread.h: abstraction of threading primitive that need to be implemented by a given port
- core: addition of py/modthread.c to implement the
_threadmodule in a port-agnostic way - core: MICROPY_PY_THREAD option to enable the
_threadmodule - core: MICROPY_PY_THREAD_GIL option to enable the GIL (threading is still possible without the GIL but one must ensure not to access mutable structures (eg list) from different threads at the same time)
- tests: thread tests in tests/thread
- unix: implementation of threading using pthreads (see unix/mpthreadport.c)
- cc3200: implementation of threading using FreeRTOS threads (see cc3200/mpthreadport.c)
The GIL is not optimised (it releases/acquires on each pending exception check in the VM) but it works correctly.
To test on unix (requires pthread library):
cd unix
make
cd ../tests
./run-tests -d thread