home *** CD-ROM | disk | FTP | other *** search
- eos="eos";
- ch1=channel();
- ch2=channel();
- ch3=channel();
- task merge(inp1,inp2,out;x) {
- n=0;
- while (true) {
- if(n==2) {out!eos;skip;}
- if(avail(inp1)) {inp1?x;if(x==eos) n=n+1;
- else out!x;}
- if(avail(inp2)) {inp2?x;if(x==eos) n=n+1;
- else out!x;}
- }};
- task source1(out) {out!1;out!3;out!eos;};
- task source2(out) {out!2;out!4;out!5;out!eos;};
- task sink(inp;x) {inp?x;while(x!=eos) {print x;inp?x;}};
- task main() {start source1(ch1); start source2(ch2);start merge(ch1,ch2,ch3);
- start sink(ch3);};
- end
-