juliusbaechle / MicroQt

Library inspired by Qt that enables event-driven applications on the Arduino platform

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is the evenloop thread safe?

xeonqq opened this issue · comments

for example when simultaneous calls to https://github.com/juliusbaechle/MicroQt/blob/master/src/EventLoop.h#L15, it will have a issue or? since your vector is also not thread safe.

My use case is I have a ESPAsyncWebServer on the esp8266, it will receive user request coming from hosted website. And the webserver runs in its own thread, I can not place it in the event loop.

You are right: the event loop is not threadsafe, which is sufficient for most Arduinos.
Since I only used plain C++ without the std library, there is no mutex available.

According to this article, ESPAsyncWebServer events run as interrupts, which means you can't use millis() or delay(), but you don't have to explicitly synchronize them with the loop thread. In this case, you should be able to use my event loop as it is.