Threads are used to allow concurrent execution of various control and system tasks. The developer has control to assign groups of tasks to specific threads, and then the assign the thread to a specific CPU in the case where there are multiple CPU-cores supported by the computer operating system.
Threads are explicitly defined in XML
Here's and example of two timed threads defined in XML:
<threads>
<!-- main thread runs 10ms -->
<timedThread
priority="10"
cpuAffinity="1"
updatePeriodInUs="10000"
threadName="UR5_IK"
path="ik_thread"
>
<invokes>
<element taskId="STOP_PERIOD_TIMER" taskPath="/ik/periodTimer"/>
<element taskId="START_PERIOD_TIMER" taskPath="/ik/periodTimer"/>
<element taskId="START_LOOP_TIMER" taskPath="/ik/loopTimer"/>
<element taskId="RUN_CURRENT_STATE" taskPath="/mc1/top_fsm"/>
<element taskId="CALC_IK" taskPath="/mc1"/>
<element taskId="PUBLISH_MANIP_STATE" taskPath="/mc1"/>
<element taskId="UPDATE_DRIVE_COMM" taskPath="/drivecomm"/>
<element taskId="PROCESS_DRIVE_MESSAGES" taskPath="/drivecomm"/>
<element taskId="STOP_LOOP_TIMER" taskPath="/ik/loopTimer"/>
</invokes>
</timedThread>
<!-- define a separate thread to handle hmi comm -->
<timedThread
priority="5"
cpuAffinity="2"
updatePeriodInUs="100000"
threadName="HMI_COMM"
path="/comm_thread"
>
<invokes>
<element taskId="RECEIVE" taskPath="/commTransferLayer"/>
<element taskId="SEND" taskPath="/commTransferLayer"/>
</invokes>
</timedThread>
</threads>
XML Example: Multiple timers under a timedThread
.
The first thread UR5_IK
runs the following tasks defined in the Data Store, where the callback handle is found.
Each cycle of the timed thread, the following task (by ID) are invoked:
The second thread, with priority 5, the comm transfer thread, handles the RECEIVE and SEND of data transfers.
The tasks themselves define the call back functions, and publish a reference to the call backs in the data store. (See Control Tasks) When the thread runs and processes its list of invoikes, a call back lookup in the data store is performed, and then the callback function is invoked.