home *** CD-ROM | disk | FTP | other *** search
- program cpdemo;
-
- {Concurrent programming demonstration program}
-
-
- {$i biosdec.pas} {Bios call declarations}
- {$i libdec.pas} {Turbo Library declarations}
- {$i concur.pas} {Concurrent programming module}
-
-
- procedure task1;
- {Installed as a concurrent program with tasknumber = 1.
- Displays the contents of a text file in its own window}
-
- const filename = 'concur.pas';
-
- var f : text;
- s : string [37];
- i : integer;
-
- begin
- window (1, 1, 40, 20); {Create task window}
- border ('Contents of file : ' + filename);
- clrscr;
- repeat
- assign (f, filename);
- {$i-} reset (f); {$i+}
- if ioresult <> 0 then writeln ('Cannot find ', filename)
- else
- begin
- while not eof (f) do
- begin
- readln (f, s);
- writeln (s);
- switchtask;
- end;
- close (f);
- end;
- claiminput;
- write ('Hit ENTER to continue ');
- readln (s);
- releaseinput;
- until false; {Note : task should never return !!!}
- end;
-
-
- procedure task2;
- {Installed as a concurrent program with tasknumber = 2.
- Displays the contents of a text file in its own window}
-
- const filename = 'biosdec.pas';
-
- var f : text;
- s : string [37];
- i : integer;
-
- begin
- window (41, 1, 80, 10); {Create task window}
- border ('Contents of file : ' + filename);
- clrscr;
- repeat
- assign (f, filename);
- reset (f);
- while not eof (f) do
- begin
- readln (f, s);
- writeln (s);
- switchtask;
- end;
- close (f);
- until false; {Note : task should never return !!!}
- end;
-
-
- procedure task3;
- {The third concurrent program. Does some simple arithmetic}
- var i, j : integer;
-
- begin
- window (41, 11, 80, 20);
- border ('Some simple arithmetic');
- clrscr;
- repeat
- for j := 1 to 10 do
- begin
- writeln;
- writeln ('Table of ', j);
- writeln ('-----------');
- for i := 0 to 9 do
- begin
- writeln (i, ' * ', j, ' = ', i*j:2);
- switchtask;
- end;
- end;
- writeln;
- writeln ('Now delaying 2 seconds');
- writeln ('Other tasks will stop!');
- delay (2000);
- until false;
- end;
-
-
- var ch : char;
- key : boolean;
-
- begin
- taskinit (600); {Allocate 3*200 paragraph's on stack segment}
- window (1, 21, 80, 25); {Create window for main program}
- border ('Main program window');
- clrscr;
- writeln ('Hit any key to issue command ');
- write ('To stop program, enter "H" ');
- installtask (ofs (task1), 200, 1); {Install first program}
- installtask (ofs (task2), 200, 2); {Install second program}
- installtask (ofs (task3), 200, 3); {Install third program}
-
- repeat
- ch := ' ';
- claiminput;
- key := keypressed;
- if not key then releaseinput;
- if not key then switchtask {Task switching is initiated here}
- else
- begin
- read (kbd, ch);
- write (': ');
- readln (ch);
- releaseinput;
- end;
- until upcase (ch) = 'H';
- end.