#include #define N 500 /* N is the number of rounds */ #define B 50 /* B is the message size, in bytes */ /* This is a ping-pong program. */ /* It sends a message back and forth "N" times between two entities. */ /* Adapted for Parsec v.1.0 on 8-27-97 by Monnica Terwilliger */ /* Declare global message types and entities */ message other_player {ename name;}; message ball {char size[B];}; entity player(int); /* Driver creates players and initiates game */ entity driver () { ename Jack, Jill; char gameball[B]; Jack = new player (1) at 1; Jill = new player (0) at 2; /* Send opponent's name to each entity */ send other_player {Jill} to Jack; send other_player {Jack} to Jill; /* Start the ping-pong game */ send ball {gameball} to Jack; } entity player (int first_player) { int trips; char gameball[B]; ename opponent; /* Wait to receive opponent's name */ receive (other_player his) /* "his" is a temporary variable */ opponent = his.name; /* Wait for the message then send it back to the opponent */ for (trips=1; trips < N; ++trips) receive (ball signal) send ball {gameball} to opponent; /* Game over -- don't return the message */ if (first_player) { printf ("Game over after %d rounds and %d byte ball size!\n",N,B); receive (ball signal) pc_exit(1); } }