1
0
Files
applications
bindings
components
acs
cmdline
epiktimer
fpspreadsheet
gradcontrols
jvcllaz
manualdock
multithreadprocs
examples
parallelloop1.lpi
parallelloop1.lpr
recursivemtp1.lpi
recursivemtp1.lpr
simplemtp1.lpi
simplemtp1.lpr
testmtp1.lpi
testmtp1.lpr
mtpcpu.pas
mtprocs.pas
mtputils.pas
multithreadprocslaz.lpk
multithreadprocslaz.pas
onguard
orpheus
powerpdf
rgbgraphics
richmemo
richview
rtfview
rx
svn
tparadoxdataset
tvplanit
virtualtreeview
virtualtreeview-new
xdev_toolkit
examples
lclbindings
wst
lazarus-ccr/components/multithreadprocs/examples/recursivemtp1.lpr

50 lines
1.1 KiB
ObjectPascal
Raw Normal View History

program RecursiveMTP1;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}
cthreads, cmem,
{$ENDIF}
MTProcs;
type
TArrayOfInteger = array of integer;
var
Items: TArrayOfInteger;
type
TFindMaximumParallelData = record
Items: TArrayOfInteger;
Left, Middle, Right: integer;
LeftMaxIndex, RightMaxIndex: integer;
end;
PFindMaximumParallelData = ^TFindMaximumParallelData;
procedure FindMaximumParallel(Index: PtrInt; Data: Pointer; Item: TMultiThreadProcItem);
var
Params: PFindMaximumParallelData absolute Data;
LeftParams, RightParams: TFindMaximumParallelData;
begin
if Params^.Left+1000>Params^.Right then begin
// compute the maximum of the few remaining items
Params^.LeftMaxIndex:=Params^.Items[Params^.Left];
for i:=Params^.Left+1 to Params^.Right do
if Params^.Items[i]>Params^.LeftMaxIndex then
end else begin
end;
end;
function FindMaximumIndex(Items: TArrayOfInteger): integer;
begin
end;
begin
SetLength(Items,10000000);
for i:=0 to length(Items)-1 do Items[i]:=Random(1000);
ProcThreadPool.DoParallel(@DoSomethingParallel,1,5,nil); // address, startindex, endindex, optional data
end.