← index #3667PR #2165
Related · high · value 5.711
QUERY · ISSUE

esp8266: multi threading

openby misisnikopened 2018-03-12updated 2018-12-06
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

mergedby dpgeorgeopened 2016-06-07updated 2016-07-10

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_ctx into an individual structure, accessed via MP_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 _thread module in a port-agnostic way
  • core: MICROPY_PY_THREAD option to enable the _thread module
  • 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

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied