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.


Hello all,


Description:


Lock-free threadpool.


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... -


- 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)
ParallelQueue: does use ParallelQueue - very efficient -
Lockfree_MPMC: does use Lockfree_SPMC
ParallelQueueh: does use ParallelQueueh - ParallelQueueh is for
educational purpose -
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 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}
ThreadPool,sysutils,syncobjs;


{$I defines.inc}


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


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


end;


var
myobj:TMyThread;
TP: TThreadPool;
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 := TThreadPool.Create(4, 20, TMyThread); // 4 workers threads and
2^20 items for each queue.


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


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


readln;


TP.Terminate;
TP.Free;


end.


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


Sincerely,
Amine Moulay Ramdane.


From: Warren on
aminer expounded in
news:c801ed23-dc85-4914-a9c7-33f097a1a3b8(a)35g2000yqm.googlegroups.com:

> Hello all,
>
>
> Why i am posting here ?
>
> Cause ADA looks like Object Pascal and the algorithms can easily
> be ported to ADA.

It's Ada, Ada, Ada, Ada, Ada, Ada, Ada, Ada, Ada, Ada, Ada, Ada, Ada,
Ada, Ada, Ada, Ada, Ada, Ada, Ada, Ada, Ada, Ada, Ada, Ada, Ada, Ada,

not ADA.

A pet peeve of mine, sorry..

Warren