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");
    }
}

Saturday, June 2, 2012

Mel Directives

In the previous Producer/Consumer example, we mention that the mel variable acts like a buffer between the Producer and Consumer. NERWous C defines two directives for the mel variable, buffer size and wait time. Let's look at this new Producer/Consumer code:
main() {
    pel Producer() p;
    pel Consumer(p);
}
(mel item val<10>) Producer () {
   try {
        while ( !timeToPunchOut() )
           ?val<20msec> = produce();
    }
    catch (val!NOREADER) {
        printf ("Consumer has done consuming. I go home too");
    }
}
void Consumer (Producer p) {
    try {
      while ( 1 )
          consume(?p!val<50min>);
    }
    catch (p!TERMINATE){
      printf ("Producer has done producing. I go home too");
    }
    catch (p!val!NOWRITER) {
      printf ("Producer has disappeared. I get out too");
    }
}
In the above code, the Producer suggests to the run-time system to allocate 10 "buffer slots" for the mel variable val. This suggestion is similar to the register declaration in the C language. The run-time system may accept or ignore the buffer size directive.

Both the Producer and Consumer also indicate how long they will wait before raising the mel exceptions NOREADER or NOWRITER. Again, these values are suggestions. The run-time system may or may not support the per call wait time directive.