Nice TWiki > Doc > CodeExamples > SimpleProducerConsumerCspExample (r1.1) TWiki webs:
Dev | Doc | Main | TWiki | Sandbox
Doc . { Changes | Index | Search | Go }
/* Please try the NoviceExamples before these examples
To compile:
   >nicec --classpath "jcspclasses.jar;nice-csp.jar" --sourcepath .. -a prodcons.jar prodcons
To run:
   java -cp "jcspclasses.jar;prodcons.jar" prodcons.fun
*/

import nice.csp;

let int MAX = 5;

void main(String[] args){
   let chan = new One2OneChannelInt();

   let p = new Producer(channel: chan);
   let c = new Consumer(channel: chan);

   par ([
          ()=>{ c.consume(); }
         ,()=>{ p.produce(); }
      ]);
}


class Producer {
   One2OneChannelInt channel;
   int count = 0;

   void produce(){
      while(count < MAX){
         count++;
         channel.write(count);
      }
   }
}

class Consumer {
   One2OneChannelInt channel;
   int count = 0;

   void consume(){
      while(count < MAX){
         count = channel.read;
         println("Consumed " + count);
      }
   }
}

/* Notes - language



*/
-- IsaacGouy - 24 Feb 2004

Topic SimpleProducerConsumerCspExample . { Edit | Attach | Ref-By | Printable | Diffs | r1.9 | > | r1.8 | > | r1.7 | More }
Revision r1.1 - 24 Feb 2004 - 02:21 GMT - IsaacGouy
Parents: WebHome > CodeExamples
Copyright © 1999-2003 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback.