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


6.2.1 Communication across two provided ports

image

Without async it is not allowed in Dezyne to call an out-event in another provided port than the provided port that was the origin of the event. The following example shows how this can be done using async.

component Async_ForkProvidedIn
{
  provides IA ppa;
  provides IA ppb;

  behaviour
  {
    bool outstanding_a = false;
    bool outstanding_b = false;
    requires dzn.async reflector_a;
    requires dzn.async reflector_b;

    [!outstanding_a] on ppa.ia(): {outstanding_a = true; reflector_a.req();}
    [!outstanding_b] on ppb.ia(): {outstanding_b = true; reflector_b.req();}
    [outstanding_a] {
      on ppa.ia(): {} // ignore second ia
      on reflector_a.ack(): {outstanding_a = false; ppb.oa();}
    }
    [outstanding_b] {
      on ppb.ia(): {} // ignore second ia
      on reflector_b.ack(): {outstanding_b = false; ppa.oa();}
    }
  }
}
interface IA
{
  in void ia();
  out void oa();

  behaviour
  {
    on ia: {}
    on optional: oa;
  }
}

In this example an in-event on one port results in an out-event on the other port. The async only decouples the resulting out-event from the context of the in-event.

image

A provides in-event on one provides port generates an out-event on the other provides port