best way to "switch" tasks

matejm wrote on Wednesday, November 06, 2013:

i have some problems how to “control” tasks… i have one main task which control others “reporting” tasks, which read data from sensors, sending data to server etc… but they’ll run occasionally some of them will run once per day others few times on month

now i’m wondering how should i do that and why is one way better than other?

a) suspending/resuming tasks
b) changing their priorities

i didn’t find any specific info at when should i use one of them… if i choose b) and raise priority to one task, scheduler won’t run other task until i don’t set low priority to it… what is diffrent if i choose way a) - i run task with highest priority and when is finished i suspend it…

best regards,

davedoors wrote on Wednesday, November 06, 2013:

If you need tasks to do these periodic actions then my answer assumes the functionality is unsuitable to be done in a software timer.

The other tasks must be tightly synchronized with the controlling task then you could have the other tasks suspend themselves when they have finished their action. The controlling task can then unsuspend them when it is time for them to perform their action again.

matejm wrote on Wednesday, November 06, 2013:

Dave, thanks for reply, tasks - actions are not peridoic… i think that suspending tasks is best choose because task is in suspended state and scheduler doesn’t have to mess with it (until i resume it )… if i changing a priority - task is in a Ready mode and scheduler will looking between more tasks (for each task at least one or more comparation)

richard_damon wrote on Thursday, November 07, 2013:

Generally i have tasks switch by having them wait on something (like a semaphore or queue) which tells them they have something to do. Trying to starts/stop tasks with resumes or priorities generally indicates that not enough effort has gone into figuring out when they are supposed to run and what they are supposed to do.

Tasks in the Blocked state don’t take attention of the scheduler.