3.1. Message chain using fthreads

Start C++ section to tut/examples/tut211.flx[1 /1 ]
     1: include "std";
     2: 
     3: thread_max := 10;
     4: message_max := 10;
     5: 
     6: var thread_count = thread_max;
     7: var message_count = message_max;
     8: 
     9: print thread_count; print " threads"; endl;
    10: print message_count; print " messages"; endl;
    11: 
    12: proc final() {
    13:   var msg:int;
    14:   var total = 0;
    15:   whilst true do
    16:     &msg <- read;
    17:     total += msg;
    18: 
    19:     if message_count == 0 do
    20:       print total; endl;
    21:     done;
    22:   done;
    23: }
    24: 
    25: proc agent() {
    26:   us := thread_count;
    27:   --thread_count;
    28:   var next =
    29:     if us > 1 then start the agent
    30:     else start the final endif
    31:   ;
    32:   var msg:int;
    33:   whilst true do
    34:     &msg <- read;
    35:     send[int] (&next) (msg+1);
    36:   done;
    37: }
    38: 
    39: var first = start the agent;
    40: 
    41: whilst message_count >0 do
    42:   --message_count;
    43:   send[int] (&first) 0;
    44:   //collect();
    45: done;
    46: 
    47: 
End C++ section to tut/examples/tut211.flx[1]