home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume27 / distributed-c-2.1 / part01 / examples / hello / hello.dc next >
Encoding:
Text File  |  1993-12-22  |  2.5 KB  |  63 lines

  1. /***************************************************************************
  2.  *                                                                         *
  3.  * @@@@  @@@ @@@@@ @@@@@ @@@@@ @@@ @@@@  @   @ @@@@@ @@@@@ @@@@       @@@  *
  4.  * @   @  @  @       @   @   @  @  @   @ @   @   @   @     @   @     @   @ *
  5.  * @   @  @  @@@@@   @   @@@@@  @  @@@@@ @   @   @   @@@@@ @   @     @     *
  6.  * @   @  @      @   @   @ @    @  @   @ @   @   @   @     @   @     @   @ *
  7.  * @@@@  @@@ @@@@@   @   @  @  @@@ @@@@  @@@@@   @   @@@@@ @@@@       @@@  *
  8.  *                                                                         *
  9.  *              A compiler for distributed programming with C              *
  10.  *                                                                         *
  11.  *                            h e l l o . d c                              *
  12.  *                                                                         *
  13.  *                 Version 1.0      CreationDate: 01.09.93                 *
  14.  *                                    LastUpDate: 01.09.93                 *
  15.  *                                                                         *
  16.  * A simple example: the Distributed C version of Kernighan and Ritchie's  *
  17.  * example "Hello world".                                                  *
  18.  *                                                                         *
  19.  ***************************************************************************/
  20.  
  21. #include <stdio.h>
  22.  
  23. #define UNLIMITED    1
  24. #define MAXPROCNUM    50
  25.  
  26. /* specification of the process Print_Greetings with the transaction Say_Hello */
  27. process spec Print_Greetings(int process_number)
  28. {
  29.     trans void Say_Hello();
  30. }
  31.  
  32. /* definition of the process Print_Greetings with the transaction Say_Hello */
  33. process body Print_Greetings(process_number)
  34. {
  35.     while(UNLIMITED) {
  36.     select {
  37.         accept Say_Hello() {
  38.         printf("Hello world! I am process %d.\n", process_number);
  39.         fflush(stdout);
  40.         }; /* a semicolon is required here! */
  41.         or terminate
  42.     }
  43.     }
  44. }
  45.  
  46. /* definition of the main process */
  47. main()
  48. {
  49.     int number_of_processes, i;
  50.     process Print_Greetings descr[MAXPROCNUM];
  51.  
  52.     printf("How many processes do you want to create? ");
  53.     scanf("%d", &number_of_processes);
  54.     /* create number_of_processes processes */
  55.     for(i=1; i<=number_of_processes; i++)
  56.     descr[i] = create Print_Greetings( i );
  57.     /* order each process to display the greetings */
  58.     for(i=1; i<=number_of_processes; i++)
  59.     descr[i]@Say_Hello();
  60.     exit(0);
  61. }
  62.     
  63.