Pages

Friday, August 18, 2017

Pel Location

Welcome » NERWous C » Pel
  1. At Attribute
  2. Location Property
  3. Down Exception
  4. Import Attribute
  5. Array Variables


At Attribute

When a task is created via a simple pel statement:
<!>producer();
it is arbitrarily assigned to a computer element (cel) in a pool of cels maintained by the CHAOS runtime environment. There are times that the work requires a specialized hardware. Like the at attribute for mel creations, the at attribute can be used with pel creations to assign a computing "location" to a task:
extern <cel> VENDOR, DISTRIBUTOR, USER;
main () {
     <mel at=DISTRIBUTOR> int store;
     <! at=VENDOR> Producer (store);
     <! at=USER> Consumer (store);
}
void Producer (<mel> int store) {
     int c;
     while ( c = Produce() )
         <?>store = c;

     <close>store;
}
void Consumer (<mel> int store) {
    try {
         while ( 1 )
             Consume(<?>store);
     } catch ( store<CLOSED> ) {
         return;
     }
}
The cel entities VENDOR, DISTRIBUTOR and USER are defined as extern. Their definition will come from a configuration file that is associated with the above NERWous C program. This configuration file is specific to the runtime environment, and allows the same NERWous C program to be run on different physical platforms.

It is also possible to hard-code the value of the cel. Like the at attribute for the mel statement, the at attribute for the pel statement can accept either a cel value or a location value:
#define VENDORURL "https://pelvendor.nerw/"
#define USERURL "https://peluser.nerw/"

    <cel> VENDOR;
    VENDOR<id> = VENDORURL;

    <! at=VENDOR> Producer (store);
    <! at=USERURL> Consumer (store);
The Producer task uses the cel variable VENDOR like before. However this time, this cel is initialized within the program with VENDORURL as the identification value. The VENDOR cel can be initialized more succinctly:
    <cel> VENDOR = { VENDORURL };
The Consumer task specifies the identification value USERURL directly. The CHAOS runtime will automatically create a cel variable with this identification value, and assign it to the Consumer task.


Location Property

The pelling task and the pelled task can find out what is the identification of the cel in use via the location property.
extern <cel> VENDOR, DISTRIBUTOR, USER;
main () {
     <mel at=DISTRIBUTOR> int store;
     <pel> prod = <! at=VENDOR> Producer (store);
     <pel> cons = <! at=USER> Consumer (store);

     printf ("Producer at [%s]", prod<location>);
     printf ("Consumer at [%s]", cons<location>);
}
void Producer (<mel> int store) {
     printf ("Running at [%s]", pel<location>);
     int c;
     while ( c = Produce() )
         <?>store = c;

     <close>store;
}
void Consumer (<mel> int store) {
    printf ("Running at [%s]", pel<location>);
    try {
         while ( 1 )
             Consume(<?>store);
     } catch ( store<CLOSED> ) {
         return;
     }
}
The pelling task, main, uses the pel variables, prod and cons, in order to access the location property. For the pelled tasks, Producer and Consumer, the location property is accessed via the default pel variable which represents the running task.


Down Exception


main () {
    <pel> task_producer = <!> Producer ();
    <pel> task_consumer = <!> Consumer (task_producer);
}
int Producer () {
    while ( 1 ) {
        int c = produce();
        if ( c == 0 ) {
           <return> c;
        }
        <release> c;
    }
}
void Consumer (<pel>tprod) {
    while ( 1 ) {
      try {
        consume (<?>tprod);
      }
      catch (tprod<ENDED>) {
        printf ("I am ending due to the Producer having ended");
        return;
      }
      catch (tprod<DOWN>) {
        printf ("I am ending due to the Producer has crashed");
        return;
      }
    }
}



Previous Next Top

No comments:

Post a Comment