- Simple Tasks
- Multiple Tasks
- Communicating Tasks
- Communicating Values
- Synchronising Tasks
- Buffered Communication
- Multiple Senders
- Conditional Tasks
Most of the library components need access to common data describing the state of the tasks being executed. The variables which maintain this state are defined by Tasks.cpp as members of the tasks_system namespace used by all the components.
Every time new_channel is called the value of next_channel, which is initialised to zero, is used to define the channel's identifier, after which it is incremented by one. Information about the state of each channel is maintained in the channels array indexed by channel identifier. The channel type is defined in channel.h.
Every time new_task is called the value of next_task, which is initialised to zero, is used to define the task's identifier, after which it is incremented by one. Information about the state of each task is maintained in the tasks array indexed by task identifier. The task type is defined in type.h.
Every time an action is added to a task, a value used to represent it is added to the code array using next_code, which is initialised to zero, as an index. The value of next_code is then incremented by one. One entry is also added to the code array for each action parameter, e.g. pause(100) requires two entries in the code array.
The active_queue variable is used to maintain a queue of task identifiers in the order they will be selected for execution. When a task is delayed waiting on a condition or for some time interval, or for communication to take place, it will be removed from the queue. When it becomes ready for execution again, it will be placed at the back of the queue. At any particular time the task at the front of the queue is the one being executed. The queue type is defined in queue.h.
When a task starts waiting on a condition, or is paused, it will be removed from the front of the active_queue and added to the waiting_set so that the system can periodically check to see which tasks are ready to continue. Normally tasks are selected for execution in the order defined by the active_queue, however they may finish waiting, and thus be remove from the waiting_set, in any order. When a task is removed from the waiting_set it is placed at the back of the active_queue. The set type is defined in set.h.
While a task is being defined, i.e. after a call of new_task and before a call of end_task, or when it is active and being executed, current_task will hold the tasks identifier.
The skip variable is used to implement the when and repeat actions.