MCA Logo
MCA Online Reference Documentation
Main Index

2.2. Using ThreadContainers

Within a group, a module can be executed in an own thread. Therefore a special thread container has to be created with specifications about period time and execution priority. While the ThreadContainer needs the enclosing group as parent, the module itself will be executed within the additional thread if the thread container is specified as parent. The following example creates a ThreadContainer with a period of 10 ms and a priority of 10. Note, that the interpretation of the priority value depends on the underlying System and is not available on Linux and Windows platforms. At the moment, only RT-Linux supports differnt priorities.

Example 2-2. Using ThreadContainers

 tTestGroup::tTestGroup(tParent *parent, bool fixit):
  tGroup(parent,"TestGroup",
  eSI_DIMENSION, eSO_DIMENSION,eCI_DIMENSION, eCO_DIMENSION,
  si_description, so_description, ci_description, co_description)
 {
   tThreadContainer* module_a_container=new tThreadContainer(this, tTime().FromMSec(10), 10);
   mModuleA *module_a=new mModuleA(module_a_container);
  .
  :

Within the constructor of mModuleA the FixIt() function is called. This informs its parent about the IO definitions. A ThreadContainer as parents then copies the IOs, i.e. its IOs are similar to the embeded modules ones. After creation only the ThreadContainer has to be connected to other modules using edges as then the IOs (which are read and written by different asynchronious threads) are safe considering asynchronious read/write access.