Pages

Saturday, June 9, 2012

NOW Directive

In addition to the buffer size and wait-time directives, the mel variable supports a no-wait access directive, called the NOW directive. Let's change our Producer/Consumer example to use the NOW directives:
main() {
    pel Producer() p;
    pel Consumer(p);
}
(mel item val<10>) Producer () {
   try {
        while ( !timeToPunchOut() )
           ?val<NOW> = produce();
    }
    catch (val!NOREADER) {
        printf ("Consumer has done consuming. I go home too");
    }
}
void Consumer (Producer p) {
    item c;
    try {
      while ( 1 ) {
          c = ?p!val<NOW>;
          if ( c == NULL ) doOtherStuff();
          else consume(c);
    }
    catch (p!TERMINATE){
      printf ("Producer has done producing. I go home too");
    }
    catch (p!val!NOWRITER) {
      printf ("Producer has disappeared. I get out too");
    }
}

No comments:

Post a Comment