[fpc-pascal] using mtprocs
johnelee0 at gmail.com
Fri Apr 19 01:39:03 CEST 2013
Thanks - however, my attempt to modify the test program by adding the exec
as below so it works in 'parallel' with the main program doesn't work, so I
must have missed something.
uses windows,classes, dos, crt, sysutils,MTProcs;
// a simple parallel procedure
procedure DoSomethingParallel(Index: PtrInt; Data: Pointer; Item:
if index=1 then
//this compression, using arc (but it could be 7z takes 30 secs)
exec('c:\windows\system32\cmd','/c c:\utils\arc a -mx tmp
for i:=1 to Index*1000000 do ; // do some work
ProcThreadPool.DoParallel(@DoSomethingParallel,1,5,nil); // address,
//main prog eg capturing the xml
for j:=1 to 10 do
begin write(j,' '); sleep(10000); end;
> > I have a program that captures xml data every 2-6 secs from a power
> > win , xp. Would like to use freearc ebvery minute or so to compress the
> > previous data in parallel w/o stopping the capture. Running arc from cmd
> > line using exec eg exec('/c arc.exe outfile infile'); The compression may
> > take 30 secs or so.
> > Is using mtprocs as in
> > http://wiki.lazarus.freepascal.org/Parallel_procedures#Getting_MTProcs
> > the best way to do this? Or threads. Any other ideas?
> mtprocs uses TThreads.
> It creates them on demand and only once and destroys them at the end of
> the program. If there is nothing to do the threads are waiting using no
> CPU cycles and can wake up very quickly. So they are like light weight
> The nice thing is that mtprocs tries to guess the number of cores and
> automatically creates this amount of threads. You can limit the number
> of threads or create more if you want. You can free the threads.
> I use mtprocs for several xml servers. One server for example
> reads files with 12 cores in parallel, scaling nicely.
> Another program of mine starts 100 pings in parallel.
> mtprocs supports recursion and exceptions.
> And it is written entirely in FPC, so it works X-platform.
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-pascal