home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / languags / modula2 / procon.fix < prev    next >
Encoding:
Text File  |  1994-07-13  |  1.3 KB  |  66 lines

  1. (*
  2.  *    Producer/Consumer Test Module
  3.  *
  4.  *    This module tests the WAIT and SEND functions
  5.  *    found in the Processes module and is adapted
  6.  *    from code found on page 346 of Advanced Modula-2
  7.  *    by Herber Schildt available from McGraw-Hill.
  8.  *
  9.  * Corrected version - David Granz, 14-Mar-87
  10.  *
  11.  *)
  12.  
  13. MODULE ProCon;
  14.  
  15. FROM Terminal IMPORT WriteLn,WriteString;
  16. FROM SYSTEM IMPORT WORD,PROCESS,ADR,NEWPROCESS,TRANSFER;
  17. FROM Processes IMPORT WAIT,SEND,StartProcess,Init,SIGNAL;
  18.  
  19. CONST
  20.   EOL = 36C;
  21.   EOT = 32C;
  22.  
  23. VAR
  24.   buf: ARRAY[0..100] OF CHAR;
  25.   S: SIGNAL;
  26.  
  27. PROCEDURE Consumer;
  28. BEGIN
  29.   LOOP
  30.     WriteString("waiting");
  31.     WriteLn;
  32.     WAIT(S);
  33.     WriteString("consumed:");
  34.     WriteString(buf);
  35.     WriteLn;
  36.   END;
  37. END Consumer;
  38.  
  39. PROCEDURE Producer;
  40. VAR
  41.   count: CARDINAL;
  42.   ch: CHAR;
  43.  
  44. BEGIN
  45.   count := 0;
  46.   LOOP
  47.     READ(ch);                   (* Clear character buffer *)
  48.     IF (ch <> EOL) AND (count < 99) THEN
  49.       buf[count] := ch;
  50.       INC(count);
  51.     ELSE
  52.       buf[count] := CHR(0);    (* Null terminator *)
  53.       SEND(S);
  54.       count := 0;
  55.     END;
  56.   END;
  57. END Producer;
  58.  
  59. BEGIN
  60.  
  61.   Init(S);
  62.   StartProcess(Consumer,1000);
  63.   Producer;
  64.  
  65. END ProCon.
  66. S............1-364-2474...2400 N81N         Procomm BBS........