Advertisement
furaidi

ThreadsTest

Aug 11th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.51 KB | None | 0 0
  1. program test5;
  2. {$mode objfpc}{$H+}
  3.  
  4. uses
  5.   cthreads, sysutils;
  6.  
  7. var
  8.   t_count: word;
  9.   counter: longword = 0;
  10.  
  11. function MyFunc (p: pointer): ptrint;
  12. var
  13.   i,j:word;
  14. begin
  15.   i:=Random(16)+1;
  16.   for J:=0 to I do begin
  17.     writeLn('Thread #',integer(p),'/',j);
  18.   end;
  19.   InterLockedIncrement(counter);
  20.   MyFunc:=0;
  21. end;
  22.  
  23. var
  24.   i:word;
  25.  
  26. begin
  27.   Randomize;
  28.   t_count:=1024;
  29.   for i:=1 to t_count do BeginThread(@MyFunc, pointer(i));
  30.   while Counter<T_count do;
  31.   WriteLn('Job is done');
  32. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement