A Simple Program



next up previous contents index
Next: Compiling and Linking Up: A First Example Previous: A First Example

A Simple Program

   

The example1.fm program creates two tasks, producer and consumer, and connects them with a channel. The channel is used to communicate a stream of integer values 1,...,5 from producer to consumer.

==

      program example1
      inport  (integer) pi
      outport (integer) po
      channel(in=pi, out=po)
      processes
         processcall producer(5, po)
         processcall consumer(pi)
      endprocesses
      end

      process producer(nummsgs, po)
      intent (in) nummsgs, po
      outport (integer) po
      integer nummsgs, i
      do i = 1, nummsgs
         send(po) i
      enddo
      endchannel(po)
      end

      process consumer(pi)
      intent (in) pi
      inport (integer) pi
      integer message, ioval
      receive(port=pi, iostat=ioval) message
      do while(ioval .eq. 0)
        print *, 'consumer received ', message
        receive(port=pi, iostat=ioval) message
      enddo
      end
=1.03   

The program comprises a main program and two process  definitions. The main program declares two port variables  pi and po. These can be used to receive (INPORT ) and send (OUTPORT ) integer messages, respectively. The CHANNEL  statement creates a communication channel and initializes pi and po to be references to this channel. The process block  (PROCESSES /ENDPROCESSES ) creates two concurrent processes, passing the port variables as arguments.

The process definitions are distinguished by the PROCESS   keyword. The producer process uses the SEND  statement to add a sequence of messages to the message queue  associated with the channel referenced by po. The ENDCHANNEL  statement terminates this sequence. The consumer process uses the RECEIVE  statement to remove messages from this message queue until termination is detected.



Steve Tuecke
Tue Aug 30 12:20:34 CDT 1994