From: aminer on

Hello all,


Why i am posting here ?


Cause ADA looks like Object Pascal and the algorithms can easily
be ported to ADA.


Description:


Lock-free threadpool with priority.


The following have been added:


- You can give the following priorities to jobs:


LOW_PRIORITY
NORMAL_PRIORITY
HIGH_PRIORITY


-- Lockfree ParallelQueue for less contention and more efficiency or
it can use lockfree_mpmc - flqueue that i have modified, enhanced and
improved... -


- Work-stealing - for more efficiency -


- Enters in a wait state when there no job in the queue, hence, it's
very efficient


Look into define.inc there is many options:


CPU32: for 32 bits architecture
MUTIPLE_PRODUCER: mutiple producer (threads)
SINGLE_PRODUCER: for a single producer (thread)


Required switches: -Sd (Delphi mode) for FPC


Please look at the examples test.pas and testpool.pas inside the
zip...


Note: testpool.pas does require Delphi 5+, test.pas works with both
FreePascal and Delphi


You can download Threadpool with priority version 1.1 from:


http://pages.videotron.com/aminer/


Language: FPC Pascal v2.2.0+ / Delphi 5+: http://www.freepascal.org/


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


Threadpool is *VERY* easy to use, here is an example:


---------------------------------------------------------------------------­--------


program test;


uses
{$IFDEF Delphi}
cmem,
{$ENDIF}
PThreadPool,sysutils,syncobjs;


{$I defines.inc}


type
TMyThread = class (TPThreadPoolThread)
//procedure ProcessRequest(obj: Pointer); override;


procedure MyProc1(obj: Pointer);
procedure MyProc2(obj: Pointer);


end;


var
myobj:TMyThread;
TP: TPThreadPool;
obj:pointer;
cs:TCriticalSection;


procedure TMyThread.MyProc1(obj: Pointer);
begin


cs.enter;
writeln('This is MyProc1 with parameter: ',integer(obj));
cs.leave;


end;


procedure TMyThread.MyProc2(obj: Pointer);
begin


cs.enter;
writeln('This is MyProc2 with parameter: ',integer(obj));
cs.leave;


end;


begin


myobj:=TMyThread.create;


cs:=TCriticalSection.create;


TP := TPThreadPool.Create(4, 20, TMyThread); // 4 workers threads and
2^20 items for each queue.


obj:=pointer(1);
TP.execute(myobj.myproc1,pointer(obj),NORMAL_PRIORITY);


obj:=pointer(2);
TP.execute(myobj.myproc2,pointer(obj),NORMAL_PRIORITY);


readln;


TP.Terminate;
TP.Free;


end.


---------------------------------------------------------------------------­-


Sincerely,
Amine Moulay Ramdane.




From: aminer on

Hello,


II have forgot to tell you that i have added also the
following:

You can now call any method with the execute() method, like this


execute(your method, parameter , priority);


In Object Pascal it looks like this:

TP.execute(myobj.myproc1,pointer(obj),NORMAL_PRIORITY);

(look inside the zipfile i have included two demos:
test.pas, and ptestpool.pas - a Parallel program of Matrix
multiply by a vector that use SSE+ -

Also, as i have promised, the workers threads now
enters in a wait state when there is no jobs in the queues ,
- now it doesn't consume the CPU when there is no jobs in the queues
-
hence, it's very efficient


And, as i have promised and as you have noticed, my threadpool
now use my lockfree ParallelQueue:
at http://pages.videotron.com/aminer/parallelqueue/parallelqueue.htm

for less contention and more efficiency...

etc.



Sincerely
Amine Moulay Ramdane.


From: Ludovic Brenta on
Amine Moulay Ramdane wrote on comp.lang.ada:
> Why i am posting here ?
> Cause ADA looks like Object Pascal and the algorithms can easily
> be ported to ADA.

Ada is not Object Pascal. Ada has built-in support for parallel
programming. Therefore, porting your Pascal library to Ada is not
"easy"; instead one would rewrite your library from scratch, using
Ada's built-in features like task types, protected types (for the job
queue), arrays of tasks (for the pool itself) and task entries to
implement a thread pool. In fact, this has already been done many
times.

I appreciate that you are trying to contribute something useful but
Ada programmers really do not need a Pascal library for thread pools.

Also, I do not think it is a good idea to post complete code on a
newsgroup. Instead, you should publish it in a version control system
on a dedicated site such as SourceForge, Berlios, gitweb, bitbucket or
mtn-host.prjek.net. Ideally there should be an associated bug tracking
system.

If you would like to discuss ideas and possible improvements to your
libraries, I think the best place on usenet would be
comp.lang.pascal.delphi.misc or comp.lang.pascal.misc. Follow-ups
there.

--
Ludovic Brenta.
From: Georg Bauhaus on
Ludovic Brenta schrieb:
> Amine Moulay Ramdane wrote on comp.lang.ada:
>> Why i am posting here ?
>> Cause ADA looks like Object Pascal and the algorithms can easily
>> be ported to ADA.
>
> Ada is not Object Pascal. Ada has built-in support for parallel
> programming. Therefore, porting your Pascal library to Ada is not
> "easy"; instead one would rewrite your library from scratch, using
> Ada's built-in features like task types, protected types (for the job
> queue), arrays of tasks (for the pool itself) and task entries to
> implement a thread pool. In fact, this has already been done many
> times.

The lock-free part is the interesting thing. The lock-free parallel
queues are the potentially patented thing in the USA, I think.
From: Ludovic Brenta on
Georg Bauhaus wrote on comp.lang.ada:
> Ludovic Brenta schrieb:
>
> > Amine Moulay Ramdane wrote on comp.lang.ada:
> >> Why i am posting here ?
> >> Cause ADA looks like Object Pascal and the algorithms can easily
> >> be ported to ADA.
>
> > Ada is not Object Pascal. Ada has built-in support for parallel
> > programming. Therefore, porting your Pascal library to Ada is not
> > "easy"; instead one would rewrite your library from scratch, using
> > Ada's built-in features like task types, protected types (for the job
> > queue), arrays of tasks (for the pool itself) and task entries to
> > implement a thread pool. In fact, this has already been done many
> > times.
>
> The lock-free part is the interesting thing.

There are Ada native implementations of lock-free data structures
including priority queues and FIFOs:

http://www.dmitry-kazakov.de/ada/components.htm
and
http://www.gidenstam.org/Ada/Non-Blocking/

> The lock-free parallel
> queues are the potentially patented thing in the USA, I think.

I do hope such patents are busted like they deserve. http://w2.eff.org/patent/

--
Ludovic Brenta.