home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / memmon.zip / TEST.PAS < prev   
Pascal/Delphi Source File  |  1997-05-10  |  1KB  |  69 lines

  1. program TestStk2;
  2.  
  3. {$X+,D+,Locinfo+}
  4.  
  5. Uses
  6.   MemMon, Os2Base, VPUtils;
  7.  
  8. function SomeFunction(x: Longint): String;
  9. begin
  10.   if x = 0 then
  11.     Result := 'x is 0'
  12.   else if x > 0 then
  13.     Result := 'x is greater than 0'
  14.   else
  15.     Result := 'x is less than 0'
  16. end;
  17.  
  18. function FacFunc(p: Pointer): Longint;
  19. var
  20.   x: Longint absolute p;
  21.   BadPtr: Pointer;
  22. begin
  23.   if x < 0 then
  24.     begin
  25.       SomeFunction(x);
  26.       GetMem(BadPtr, 500);
  27.       FacFunc := 0;
  28.     end
  29.   else
  30.     if x = 0 then
  31.       begin
  32.         Getmem(BadPtr, 21);
  33.         FacFunc := 1
  34.       end
  35.     else
  36.       FacFunc := FacFunc(Ptr(x-1))*x;
  37. end;
  38.  
  39. var
  40.   tid1, tid2 : Longint;
  41.   p: Pointer;
  42.  
  43. begin
  44.   { Allocate some memory to lose }
  45.   GetMem(P, 100);
  46.  
  47.   { Allocate some memory, and free it later }
  48.   GetMem(P, 88);
  49.  
  50.   { Start a few threads }
  51.   tid1 := VPBeginThread(FacFunc, 8192, Ptr(10));
  52.   tid2 := VPBeginThread(FacFunc, 8192, Ptr(-2));
  53.  
  54.   { Wait for all threads to complete }
  55.   DosWaitThread(tid1, dcww_Wait);
  56.   DosWaitThread(tid2, dcww_Wait);
  57.  
  58.   { Free the memory allocated earlier }
  59.   FreeMem(P, 88);
  60.  
  61.   { Display standard report }
  62.   DisplayStandardData;
  63. end.
  64.  
  65.  
  66.  
  67.  
  68.  
  69.