Globally Defined Task Handles

I was wondering if there are any reasons to avoid defining task handles globally. I have a multi file project where the main calls several functions across multiple c files to create a series of tasks and I would like to be able to immediately put some of the tasks in a suspended state before the scheduler begins. As the task handles for these tasks are defined locally to the c files used to create the tasks, I am unable to suspend each task in the main. I would like to define these task handles globally but I didn’t know if there are any unforeseen consequences of doing this. I am also open to suggestions to the best way to do this if globally defining the tasks handles isn’t the best option.

Why suspending tasks which are not running ? Besides the warning that suspend/resume are almost always not the right way for task synchronization.
However, a task handle is just a variable and can be used the same way as other global variable.

1 Like

As Hartmut says, rather than suspending, using a synchronization primitive is normally a better choice (Semaphore or Direct-to-Task notification) and have the task start then immediately block waiting to be given something to do.

Also, as he said, making the handle global isn’t an awful thing, if one task needs to notify another, it needs some way to reference that task, and that means either making the handle global, or passing it into each task that needs it some how.

2 Likes