components/multithreadprocs/examples/simplemtp1.lpr
raw| 1 | program SimpleMTP1; |
| 2 | |
| 3 | {$mode objfpc}{$H+} |
| 4 | |
| 5 | uses |
| 6 | {$IFDEF UNIX} |
| 7 | cthreads, cmem, |
| 8 | {$ENDIF} |
| 9 | MTProcs; |
| 10 | |
| 11 | // a simple parallel procedure |
| 12 | procedure DoSomethingParallel(Index: PtrInt; Data: Pointer; Item: TMultiThreadProcItem); |
| 13 | var |
| 14 | i: Integer; |
| 15 | begin |
| 16 | writeln(Index); |
| 17 | for i:=1 to Index*1000000 do ; // do some work |
| 18 | end; |
| 19 | |
| 20 | begin |
| 21 | ProcThreadPool.DoParallel(@DoSomethingParallel,1,5,nil); // address, startindex, endindex, optional data |
| 22 | end. |
| 23 |