Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming > #1713

Re: About my threadpool engine...

From "aminer" <aminer@videotron.ca>
Newsgroups comp.programming.threads, comp.programming
Subject Re: About my threadpool engine...
Date 2012-06-03 11:31 -0500
Organization A noiseless patient Spider
Message-ID <jqg00e$34t$1@dont-email.me> (permalink)
References <jqfumj$r5a$1@dont-email.me>

Cross-posted to 2 groups.

Show all headers | View raw


Hello,


As you will notice my threadpool engine is a simple and efficient threadpool 
engine , i have designed it like that to easy  the learning step for those 
who want to learn how to implement a simple and efficient threadpool.


On a multicore system, your goal is to spread the work efficiently among 
many cores so that it does executes simultaneously. And performance gain 
should be directly related to how many cores you have. So, a quad core 
system should be able to get the work done 4 times faster than a single core 
system. A 16-core platform should be 4-times faster than a quad-core system, 
and 16-times faster than a single core...

That's where my Threadpool is usefull , it spreads the work efficiently 
among many cores. Threadpool (and Threadpool with priority) consist of 
lock-free thread safe/concurrent enabled local FIFO queues of work items, so 
when you call ThreadPool.execute() , your work item get queued in the local 
lock-free queues. The worker threads pick them out in a First In First Out 
order (i.e., FIFO order), and execute them. .


The following have been added to Threadpool:



- Lock-free_mpmc - flqueue that i have modified, enhanced and improved... -

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

- The worker threads enters in a wait state when there is 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.

Work-Stealing scheduling algorithm offer many feature over the ordinary 
scheduling algorithm:

  1.. Effective:
    a.. Using local queues, this will minimize contention.
  2.. Load Balancing:
    a.. Every thread can steal work from the other threads, so Work-Stealing 
provides implicitly Load Balancing.


My Threadpool allows load balancing, and also minimize contention.



Thank you.
Amine Moulay Ramdane.




"aminer" <aminer@videotron.ca> wrote in message 
news:jqfumj$r5a$1@dont-email.me...
>
> Hello,
>
> In my threadpool engine the worker threads enters in a wait state
> when there is no job in the lock-free queues - for more efficiency -
>
> you can download the source code from:
>
> http://pages.videotron.com/aminer/
>
> but if you look at the threadpool engine source code i am using
> the following  code on the producer side:
>
> ---
> events[local_balance].setevent;
> ---
>
> and using the following code on the consumer side
> :
> ---
>
> 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;
> --
>
> So a question follows..
>
> If for example the consumer thread is on
> FThreadpool.events[self.threadcount].waitfor(INFINITE);
>
> and it receives two items before entering  the
> FThreadpool.events[self.threadcount].resetevent;
> can it forget to process the second item cause the consumer thread
> will reset the event but one item will still be on the queue...
>
> Answer:
>
> No, it will still process correctly the second item cause we are catching
> the number of items with the following code on the consumer side:
>
> ---
> if ThreadPool.Queues[self.threadcount].count <> 0
> then continue;
>
> for i:=0 to FThreadpool.Fthreadcount-1 do 
> count:=count+FThreadPool.Queues[i].count;
> ---
>
>
>
>
>
>
> Thank you.
> Amine Moulay Ramdane.
>
>
>
> 

Back to comp.programming | Previous | NextPrevious in thread | Find similar


Thread

About my threadpool engine... "aminer" <aminer@videotron.ca> - 2012-06-03 11:09 -0500
  Re: About my threadpool engine... "aminer" <aminer@videotron.ca> - 2012-06-03 11:31 -0500

csiph-web