Next: , Previous: , Up: Applications of ‘async'   [Contents]


6.2.2 Fork a required event across two provided ports

image

Async can also be used to fork an event to two different provides ports. A similar argument applies here that without async circular references could be the result. The code is shown below:

component Async_ForkRequiredOut
{
  provides IA ppa;
  provides IA ppb;
  requires IB rp;

  behaviour
  {
    requires dzn.async() reflector;

    on ppa.ia(): rp.ib();
    on ppb.ia(): rp.ib();
    on rp.ob(): {reflector.req(); ppb.oa();}
    on reflector.ack(): ppa.oa();
  }
}

interface IA
{
  in void ia();
  out void oa();

  behaviour
  {
    on ia: {}
    on optional: oa;
  }
}
interface IB
{
  in void ib();
  out void ob();

  behaviour
  {
    bool is_active = false;
    on ib: is_active = true;
    [is_active] on inevitable: {ob; is_active = false;}
  }
}

At the reception of an out-event in the required port directly one of the out-events to a provided port is generated together with the sync.req. At the subsequent firing of the sync.ack the out-event to the other provided port is generated.

image

Forking an event over two provides interfaces triggered by a requires out-event