Can we do Task,Priority with Particle?

Hi.

I want to know there is any solution to handle task , priority and interrupt ?

Eg.

We have T1 and T2 and T2 has higher priority than T1. If T1 & T2 are trigger to run at the same time somehow. T2 will get right to interrupt T1 to run first. and T1 must wait until T2 finish then T1 can resume remaining task until finish

Yes, sort of, for a small number of tasks. You cannot use software timers, as they share a single queue and run sequentially at the same priority.

What you can do is run each in a separate thread. Each thread can have its own priority. Higher priority threads will interrupt a lower priority thread that has not yet yielded.

If your task is periodic you can use os_thread_delay_until to wait until its time to start. If it’s triggered by an event you can use a queue.

The caveats are that the FreeRTOS scheduler only interrupts a thread a 1 millisecond intervals if it does not yield. And since each thread has its own stack, you can run low on RAM if you have too many.

https://docs.particle.io/datasheets/app-notes/an005-threading-explainer/

1 Like