Pages

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.

No comments:

Post a Comment