home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
vp21beta.zip
/
AEXMPSRC.RAR
/
RATRACE
/
RATRACE.PAS
Wrap
Pascal/Delphi Source File
|
2000-08-15
|
2KB
|
86 lines
{█▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█}
{█ █}
{█ Virtual Pascal Examples. Version 2.1. █}
{█ Multi-threaded example █}
{█ ─────────────────────────────────────────────────█}
{█ Copyright (C) 1995-2000 vpascal.com █}
{█ █}
{▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀}
program RatRace;
{$PMTYPE VIO}
{$X+,Delphi+,Use32+}
uses
VpSysLow, Crt, Dos;
const
RatColors: array[1..8] of Byte =
( DarkGray ,
LightBlue ,
LightGreen ,
LightCyan ,
LightRed ,
LightMagenta ,
Yellow ,
White
);
RatBody: String[11] = '---<O[x]Oo.';
FinishDrawPos: Integer = 16;
var
I: Integer;
ThreadId: Longint;
ScreenSemaphore: Longint;
const
Idx: Integer = 0;
threadvar
Number: Integer;
function Rat( P : Pointer): Longint;
var
Step, S: Integer;
begin
Step := 1;
Inc(Idx);
Number := Idx;
repeat
SemRequestMutex(ScreenSemaphore, semInfinite);
TextColor(Longint(p));
S := Step;
if Step <> 1 then Dec(S);
GotoXY(S, 2 + Number * 2);
RatBody[7] := Chr(Number + Ord('0'));
if Step <> 1 then Write(' ');
Write(RatBody);
Inc(Step);
if WhereX = 80 then Break;
SemReleaseMutex(ScreenSemaphore);
Delay(Random(300));
until False;
GotoXY(FinishDrawPos, 24);
Inc(FinishDrawPos);
Write(Number);
SemReleaseMutex(ScreenSemaphore);
end;
begin
ScreenSemaphore := SemCreateMutex(nil, False, False);
TextMode(CO80);
ClrScr;
TextColor(White);
Writeln('Virtual Pascal multi-thread example v2.1 (C) 1995-2000 vpascal.com' );
Write(' The Rat Race!');
GotoXY(1, 24);
Write('Finish order: ');
GotoXY(25, 25);
Write('Press any key to exit');
for I := Low(RatColors) to High(RatColors) do
BeginThread(nil, 16*1024, Rat, Pointer(RatColors[I]), 0, ThreadId);
ReadKey;
end.