Hello,
Since my threadpool engine is using lockfree_mpmc
I had to port lockfree_mpmc to 64 bits architecture an
this was easy , i had to change two thinks, first i had to
change the longword type to use a qword type (8 bytes types),
and also i had to change the CAS to support the 64 bits architecture.
I have changed also the following inside my thread pool engine:
Before entering the wait state the worker threads have to do a test like
this: If ThreadPool.Queues[self.threadcount].count <> 0 Then continue
Like this
--
If ThreadPool.Queues[self.threadcount].count <> 0
Then continue;
for i:=0 to FThreadpool.Fthreadcount-1 do
count:=count+FThreadPool.Queues[i].count;
if count=0 then
begin
FThreadpool.events[self.threadcount].waitfor(INFINITE);
FThreadpool.events[self.threadcount].resetevent;
end;
---
And the following have been added to Threadpool:
Lock-free_mpmc - flqueue that i have modified, enhanced and improved... -
1. It uses a lock-free queue for each worker thread and it uses
work-stealing - for more efficiency -
2. The worker threads enters in a wait state when there is no job in the
lock-free queues - for more efficiency -
3. You can distribute your jobs to the worker threads and call any method
with the threadpool's execute() method.
Here is the first change for 64 bits architecture in lockfree_mpmc:
--
type
{$IFDEF CPU64}
long = qword;
{$ENDIF CPU64}
{$IFDEF CPU32}
long = longword;
{$ENDIF CPU32}
---
and here is the CAS in lockfree_mpmc that i have changed to support
the 64 bits architecture:
--
function CAS(var Target:long;Comp ,Exch : long): boolean;assembler;stdcall;
asm
{$IFDEF CPU64}
mov rax, comp
lock cmpxchg [Target], Exch
setz al
{$ENDIF CPU64}
{$IFDEF CPU32}
mov eax, comp
mov ecx,Target
mov edx,exch
lock cmpxchg [ecx], edx
setz al
{$ENDIF CPU32}
---
And the Object Pascal language was fun fun...
And here is where you can download Lazarus for 64 bits architecture:
http://www.lazarus.freepascal.org/
And here is where you can download Freepascal for 64 bits architecture:
http://www.freepascal.org/
Thank you,
Amine Moulay Ramdane.