Is there any example how to run code multithreaded?
Let’s say play music, listening to voice commands while run line following program?
Is there any example how to run code multithreaded?
Let’s say play music, listening to voice commands while run line following program?
In Python there is probably better… It seems the chip allows it. It’s not great for music but it works.
Thanks for reply. Do you mean that if I need a multithreaded tasks I have to make some separate forever loops running from CyberPi start and they will run in parallel asynchronously?
Hi Showman,
Look at the generated code. I think we are talking about 2 separate event loops for block programming. In Python, I didn’t check. However, to answer your question, the ESP32 can perform Multitread tasks.
Makeblock will tell you more, I’m sure.
I haven’t asked Makeblock, so this is speculation, but I believe each block group that starts with an event block is a separate thread in Python. However, all threads are pinned to the same core, and there’s also the Global Interpreter Lock, so the threads run concurrently on one core, not in parallel on multiple cores.
This means it’s safe to share global variables between threads.
Here’s what I found about multithreading with MicroPython on ESP32 (although it mentions FreeRTOS, not CyberOS):
https://forum.micropython.org/viewtopic.php?t=7776
https://forum.micropython.org/viewtopic.php?f=18&t=8610
@FluffusCatus @Showman @Crackel Yes, it is sage and easy to multithread with mBot Neo. And yes, you can use multiple variables across threads.
Yes, it can run some block groups simultaneously, but it you start play music using note sentences and do some other commands like blinking lights or random movements you will see that music is stuck time to time.
So in my opinion there is no real multithreading implemented.
@Showman @everyone Here is an example of how to ‘Multithread’ the mBot Neo (it is just hard with blocks):
Let me know if you have any questions about it.
https://ide.mblock.cc/share.html?3991194&authuser=0