Is mp_sched_schedule thread safe?

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
bokolob
Posts: 11
Joined: Tue Mar 09, 2021 7:03 pm

Is mp_sched_schedule thread safe?

Post by bokolob » Fri Mar 12, 2021 4:28 pm

Hello.

I work with a9g micropython port. It's a gsm+gps chip. Documentation is extremely poor, but it's known that chip contains two cores, and simple operating system with threads. Currently one of threads runs event loop, and second runs micropython. User can define callbacks in python to be called from event-loop. Such as SMS handler, incoming call, etc. But there is also some C code supporting that callbacks.
Current realization of it does one thing that I consider wrong - memory allocation. For me such calls aren't different from IRQ handlers, and can corrupt something in memory, or even worse, because threads are real and continue to work during this calls.

Example of code that is called from callback - https://github.com/bokolob/micropython/ ... lar.c#L692

So now my questions :)
1) Am I right that memory allocation is strongly prohibited in such callbacks?
2) Is mp_sched_schedule thread safe? OS contains mutexes and critical sections primitives, and they can be used if necessary.

Post Reply