// ************************************************************************** //
//                                                                            //
//    eses                   eses                                             //
//   eses                     eses                                            //
//  eses    eseses  esesese    eses   Embedded Systems Group                  //
//  ese    ese  ese ese         ese                                           //
//  ese    eseseses eseseses    ese   Department of Computer Science          //
//  eses   eses          ese   eses                                           //
//   eses   eseses  eseseses  eses    University of Kaiserslautern            //
//    eses                   eses                                             //
//                                                                            //
// ************************************************************************** //
// Measure the speed of a vehicle by counting the number of centimeters taken //
// within every second. Note the the speed remains constant until a new event //
// on second occurs. The example is taken from the Esterel primer.            //
// Remark: This version is just for discussion is contains some bugs.         //
// For example, it yields a write conflict if at some time t, we have cm&!sec //
// and at time t+1, we have sec since then dist will be possibly assigned     //
// different values. Moreover, if cm&sec holds, cm is not counted!            //   
// The program has an initial state and two further states where the dataflow //
// is the same and as follows:                                                //
//          sec ==> speed = dist; dist = 0;                                   //
//     !cm&!sec ==> nothing                                                   //
//      cm&!sec ==> next(dist) = dist+1                                       //
// ************************************************************************** //

module SpeedWithBugs(event ?centimeter,?second,nat !speed) {
   nat distance;
   loop {
      distance = 0;
      abort {
         every(centimeter)
            next(distance) = distance + 1;
      } when(second);
      speed = distance;
   }
}