home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
pascal
/
library
/
dos
/
multtsk
/
cpm25d
/
mtest.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1994-04-28
|
3KB
|
131 lines
{$I cpmswitc.inc}
{--------------------------------------------------------------------------
MTEST.PAS (Program for testing message-passing)
This program requires the CPMULTI Multitasking Toolkit and Turbo Pascal
5.0 or later.
January 1994
Copyright (C) 1994 (USA) Copyright (C) 1989-1994
Hypermetrics Christian Philipps Software-Technik
PO Box 9700 Suite 363 Duesseldorfer Str. 316
Austin, TX 78758-9700 D-47447 Moers
Germany
This demo illustrates the most basic use of the message-passing
functions of the CPMulti kernel.
---------------------------------------------------------------------------}
program MTest;
uses Dos, Crt, CpMulti;
var MessageBuffer : String;
SubNo : TaskNoType;
BeepNo : TaskNoType;
{-----------------------------------------------------------------------------}
procedure TaskMsgOut(Txt : string);
{ Safe output of a string. }
begin
BindCPU;
Writeln(txt);
ReleaseCPU;
end;
{-----------------------------------------------------------------------------}
{$F+}
procedure Beep(P:Pointer);
{ First subtask. }
begin
repeat
Sound(200);
Delay(5);
NoSound;
until Keypressed;
TaskMsgOut('Beep: Sending to SubTask...');
if Send(SubNo,@MessageBuffer,Length(MessageBuffer)+1,Wait) <> Task_OK then
Writeln('Beep: Receive status not OK.')
else
Writeln('Beep: Message was received correctly!');
TaskMsgOut('Beep: Terminating the demo...');
Terminate;
end;
{-----------------------------------------------------------------------------}
procedure SubTask(P:Pointer);
{ Second subtask. }
var Message : String;
begin
TaskMsgOut('SubTask: Started! - Sleeping for 5 seconds!');
Sleep(Seconds(5));
TaskMsgOut('SubTask: Attempting to Receive with Wait...');
if Receive(BeepNo,@Message,Wait) <> Task_OK then
TaskMsgOut('SubTask: Error in Receive!')
else
TaskMsgOut('SubTask: Received: '+Message);
TaskMsgOut('SubTask: Getting a message from the sender, if available...');
if Receive(AnyTask,@Message,NoWait) <> Task_OK then
TaskMsgOut('SubTask: Error in Receive!')
else
TaskMsgOut('SubTask: Received: '+Message);
Writeln('SubTask: Message came from task #',ReceivedFrom);
TaskMsgOut('SubTask: Terminating...!');
Terminate;
end;
{$F-}
{-----------------------------------------------------------------------------}
begin
ClrScr;
MessageBuffer := 'This is a message.';
Writeln('MasterTask: Starting the Beep task!');
BeepNo := CreateTask(Beep,NIL,Pri_User,500);
if BeepNo < 0 then
Writeln('MasterTask: Error in creating the Beep task!');
Writeln('MasterTask: Start of SubTask!');
SubNo := CreateTask(SubTask,NIL,Pri_User,1000);
if SubNo < 0 then
begin
Writeln('MasterTask: Error in creating SubTask!');
Halt;
end;
Sleep(Seconds(1)); { Let SubTask become active. }
Writeln('MasterTask: Now we are waiting for receipt of the message.');
if Send(SubNo,@MessageBuffer,Length(MessageBuffer)+1,Wait) <> Task_OK then
Writeln('MasterTask: Receive status not OK.')
else
Writeln('MasterTask: Message was received correctly!');
Writeln('MasterTask: Sleeping for 2 seconds...');
Sleep(Seconds(2));
Writeln('MasterTask: <RETURN> will terminate the demo.');
Readln;
NoSound;
end.