Sunday, March 2, 2008

Thread Pool implementation using c++

I was browsing through some Design Patterns over the internet, and I recently came across the Thread Pool pattern. My natural reaction was to google around for some implementations.

I liked Blake Thompson's win32 implementation on Intel's website. Inspired from it, I thought of writing an implementation for unix/linux platform.

ThreadPool class manages all the ThreadPool related activities. This includes keeping track of idle threads and synchronizations between all threads.

ThreadPool class uses a WorkerThread class.

Now this WorkerThread is having a virtual function executeThis().
The user needs to subclass WorkerThread and implement executeThis() to assign the tasks.

You can download the code and documentation from http://code.google.com/p/cppthreadpool/
This code is licensed under GPL v3. So feel free to use it, modify it, and whatever it.

I have currently tested it under cygwin environment, but I am expecting it to work in unix and linux environments as well (since it uses POSIX threads). It will be great if someone with unix/linux environment can test it.

If you have any doubts about how to use this Thread Pool implementation, then please feel free to ask me at shobhitgupta12@gmail.com

13 comments:

Anonymous said...

Does not work! Add printf to your SampleWorkerThread to see why...

Anonymous said...

I've just tested it too

it's also not working here (debian lenny)

Shobhit said...

Sorry that I left this unattended.

Recently I got a chance to fix all the issues. And now it works perfectly. Tested with Ubuntu 9.1.

Denis Cheremisov said...

Why do you use semaphores? It's slow. Read somewhere about using pthread conditional variables

Anonymous said...

42256.....52335

Anonymous said...

Good lord is that horrible code.

Anonymous said...

[url=http://dcxvssh.com]CFTuihIiCpjDPO[/url] , RZDNPoWetzdS , http://yuxeflk.com

Anonymous said...

Great write-up guys, I really like the infographic!


Also visit my weblog; muscle building weight training programme

Anonymous said...

Thanks a lot! Happy you're here!

my homepage arrow metal shed assembly instructions

Anonymous said...

this really is quite simple genuinely superman wins hands down
there are a million approaches superman can kill the hulk i will discuss several then use your imagination.



Here is my webpage; Keni Styles Superman Stamina Free Video

Anonymous said...

Why women constantly state that cock dimension
does not subject when u appear at guys looking
for guys or m4m page on craigslist all everybody desires is really a huge
one? r gay guys and straight women that diverse? also
despite the fact that that girls r smaller sized and weaker y do they deal
with the pain much better once i give it to them from the rear finish
than when i give men? the m4m web page is beneath informal encounters if u wanna try it out.


My blog - how to get a girlfriend

Anonymous said...

This article doesn't point out whether or not the new stress cooker is stainless-steel, cast aluminum, or other metal. My old pressure cooker was forged aluminum, a metallic I now not consider acceptable since it's .
.. reactive...? (what's appropriate reverse of "non-reactive"?)

My blog; metabolic cooking book review

Anonymous said...

Just to become certain. would you not recognize the idea of
all is energy?. . Because here's the offer: Digital Aristotle's been about considering that.
. Oh..Aristotle. . . Would you see a linear existence in front of you?

Indeed, correct? Now what is energy? It really is all possibilities for all.
So when you attended class (which I dont consider you did, i
believe you're a script regurgitated by the overarching management? program), If you attended course, did it ever cross your mind Every single schooling is individualized?

My website; attract women through body language ()