I found threads on the esp32 to be not reliable and I would like to know if anyone is using theme with success? Am I the only one to experience issues with theme?
First things first:
I use threads to do blocking IO operations like socket.getaddrinfo and ussl.wrap_socket.
At first I implemented a long running thread which pops functions from a list and executes theme. -> This did not work as in the presence of exceptions (or something else which I am not understanding) the thread somehow deadlocked/ceased operation.
Next I tried with "one blocking function per thread". So, for every function to execute in a thread, a new thread is started which will exit once the function is processed. Even with that approach some threads never will return ... In the end this manifests in that no new threads can be started due to some limit (memory for stack or task count?, I don't know).
The BAD:
I only experience this behavior of deadlocking thread in a fairly complete application. Until now I was not able to reproduce this issue with a "simple" case.
The speculations:
At first glance I thought, that the _thread deadlocks on some lock like the GIL. Investigating all MP_THREAD_GIL_EXIT(); / MP_THREAD_GIL_ENTER(); in the codebase I don't think the problem is here.
Reading the comments in modthread.c (see bleow) and my observation that in the presence of exceptions the thread dies, I am asking myself is: What happens if a pending exception is handled by another thread (can this even happen? soft interrupts?)? Will it jump to the stack of the thread which raised the exception?
Code: Select all
// TODO set more thread-specific state here:
// mp_pending_exception? (root pointer)
// cur_exception (root pointer)
Cheers
This