[fpc-pascal] using mtprocs

Mattias Gaertner nc-gaertnma at netcologne.de
Thu Apr 18 23:17:37 CEST 2013

On Thu, 18 Apr 2013 21:46:23 +0100
John Lee <johnelee0 at gmail.com> wrote:

> I have a program that captures xml data every 2-6 secs from a power sensor,
> 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.


More information about the fpc-pascal mailing list