mbeddr / mbeddr.core

The mbeddr core. An extensible C
Eclipse Public License 2.0
224 stars 77 forks source link

ScheduleSpecificationInComponent transformation issue using generation strategy pthreads #1797

Closed wuryel closed 4 years ago

wuryel commented 6 years ago

When transforming CyclicConstraintas child child of ScheduleSpecificationInComponentthe reference to the function implementing the task is lost using the generation strategy pthreads for concurrency. 1) The TaskInComponentis transformed into a Function. This task function is refered to by the nameof<Function> as parameter of pthread_create(...). 2) The task function is transformed into a Runnableand the reference within nameof<Function> is lost.

This seems to be related to #517

For example, the following code doesn't transform correctly:

exported component someComponent extends nothing { 

  void init() <= on init { 
    report(0) msg.compsInitialzed() on/if; 
    start schedAMP and continue; 
  } runnable init 

  schedule spec schedAMP {                                         
      cyclic CompCyclicTask id 99 period 1000 ms offset <no offset>;
  }

  exported cyclic task CompCyclicTask { 
    report(-1) msg.componentCyclicTick() on/if; 
  } 
wuryel commented 6 years ago

This seems to be part of an even bigger issue that pops up when having tasks embedded in components. When the task function (generated from Task, TaskInComponent) that is transformed into a Runnable (see step 2 above) is transformed back into a Function it is (like all runnables) augmented with an additional parameter void* ___id to hold a reference to the component instance data. This task function is registered with the 'pthread_create' at the OS (code generation for this doesn't work, see above). This additional parameter (___id) does not hold valid data when the function is called back from the OS and as a consequence all accesses to component data within the task function will result in a segmentation fault.

So, if I understood this correctly, in order to have the data available in the task, we'll need to add a reference to the component instance data to the task, see here and here, respectivelly. For the task function the transformation of a runnable to a function as done here is invalid also: The additional parameter ´___id´ is invalid and the component instance data must be retrieved from the task data.

wuryel commented 4 years ago

Code generation for components with embedded tasks works fine (only) if the component instance is visible from the component definition. (e.g. in the same implementation module or in an imported implementation module).

This is since the NameOfFunctionExpression is reduced to a NameOfComponentReferenceFunction that requires a component instance.