Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.
1695 Discussions

Thread Pool Engine version 1.3 - stable version - is here ...


Hello all,

I have updated Threadpool to version 1.3 - a stable version -

Lock-free ParallelQueuerb and lock-free RingBuffer have been added

Author: Amine Moulay Ramdane

Language: FPC Pascal v2.2.0+ / Delphi 5+:

Operating Systems: Win , Linux and Mac (x86).


Lock-free Thread Pool Engine.

The following have been added:

-- Lockfree ParallelQueue for less contention and more efficiency

or it can use lockfree_mpmc - flqueue that i have modified, enhanced

and improved... - ...

- It uses a lock-free queue for each worker thread and work-stealing

- for more efficiency -

- The worker threads enters in a wait state when there no job in the

lock-free queues - for more efficiency -

- You can distribute your jobs to the worker threads and call any

method with the threadpool's execute() method.

Look into there is many options:

ParallelQueue: it uses lock-free ParallelQueue - very efficient -

Lockfree_MPMC: it uses lockfree_MPMC

ParallelQueuerb: it uses lock-free ParallelQueuerb (New)

RingBuffer: it uses lock-free RingBuffer (New)

SINGLE_PRODUCER: for a single producer (thread)

MUTIPLE_PRODUCER: mutiple producer (threads)

CPU32: for 32 bits architecture

Required FPC switches: -O3 -Sd -dFPC -dWin32 -dFreePascal

-Sd for delphi mode....

Required Delphi switches: -DMSWINDOWS -$H+

For Delphi 5,6,7 use -DDelphi

For Delphi 2005,2006,2007,2009,2010+ use the switch -DDELPHI2005+

Please look at the examples test.pas,test_pool.pas and

test_thread.pas insode the zip...

Note: test_pool.pas does require Delphi 5+, test.pas and

test_thread.pas works with both FreePascal and Delphi

You can download the new and stable version 1.3 from:

My Threadpool is VERY easy to use, and here is a page

that i wrote about it:


Amine Moulay Ramdane.

0 Kudos
2 Replies

Skybuck Flying wrote:
> I would like to see performance comparisions, against
> Delphi's own TThread and/or other windows methods ?
> [...]
> and why your Thread Pool Engine would be better might also help ;)

And how will you load balance the workload efficiently,
and also minimize contention...
and not start threads for each job...
with just TThread ?

Please read again:

My Threadpool is very efficient and very easy to use...

Take care..

Amine Moulay Ramdane.

0 Kudos

Skybuck Flying wrote:
>I implemented my own "blocking queue" using semaphares and critical section
>(mutex). [...]

I don't think blocking queues are as efficient as lock-free queues

Just look at the difference between three lock-free algorithms

You can easily notice the difference between those lock-free
algorithmns just by setting the options in and
runnning test_thread1.pas

Now, just imagine what will be the difference between a
lock and a lock-free algorithm ? i really think lock-free
algorithms are very efficient.

Also, i have used in my Thread Pool Engine not just one queue
but many lock-free queues - for each worker thread - to minimize
contention... and work-stealing to load balance the workload

>Also your code's layout/indentation looks very bad...
>(at least some of the test programs look bad)...

Common ! the code is not so bad..

And also, i give much more importance to 'logic' than to code..

>Also your code seems to use all kinds of external dll's/libraries...
>which is undesirable... this could also lead to security risks...
>what's inside the dll's ?!? Virus/trojans maybe ?

I have just used the TBB memory manager in Delphi
- look at cmem.pas inside the zip - you can - if
you want - download them yourself from the intel

FPC doesn't need the TBB memory manager...

>Furthermore your source code uses assembler here
>and there where it might or might not be necessary...
>like "cas"... windows already have methods for
>"interlock exchange" and what not...

I have decided to put the assembler code for educational
purpose also...

>Your most interesting unit so far is the parallel hash list...
>hashes might not always be usefull though... but still it
>could be interesting.

I also love ParallelHashList...

>Might be a lot of work for you... so I understand if you
>don't want to do that...


Amine Moulay Ramdane.

0 Kudos