Discussion:
Thread Pool Performance in real-time applications
(too old to reply)
Jack
2010-04-22 03:32:01 UTC
Permalink
Dear all,
As my game application require more than 12 mobile units to do pathfinding
at the same time, I wonder if I implement a thread pool (and that means to
use
a task queue for awaiting tasks) for those objects, would that really affect
the overall performance
of the application? ( I mean some objects would wait for their turns and
standing still for a couple of minutes)
And are there any good examples to demostrate how to use a thread pool? I
looked codeguru and code project
and I want some more examples.
Thanks
Jack
Jack
2010-04-22 03:49:54 UTC
Permalink
Also if contrarly, If I implement 12 independent threads for each object.
Would that be too insane and totally bog down for a single core CPU?
Thanks
Jack
Ulrich Eckhardt
2010-04-22 07:14:17 UTC
Permalink
Post by Jack
As my game application require more than 12 mobile units to do
pathfinding at the same time, I wonder if I implement a thread
pool (and that means to use a task queue for awaiting tasks) for
those objects, would that really affect the overall performance
of the application?
If you have more than one core, using multiple threads can give you a
performance gain. However, if the threads each lock a mutex on a shared map
where they search their path, you obviously don't get anything. Also, if
the operations are partially IO-bound and partially CPU-bound, you would
already get an advantage for a single CPU.

General suggestion: Use one more thread than you have CPUs.

Concerning your question about a thread pool, don't bother now. If you start
implementing the task queue, you can easily change the implementation from
synchronous execution to using a thread pool without affecting the overall
design.

Uli
--
C++ FAQ: http://parashift.com/c++-faq-lite

Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
Faisal
2010-04-22 12:04:42 UTC
Permalink
From Win2000 onwards windows provides thread pool
http://msdn.microsoft.com/en-us/library/ms686760%28VS.85%29.aspx

Note that these APIs have undergone some significant changes in
Windows Vista.

If you are trying implement thread pool by your own, use the concept
of IO completion ports. You can create a number of threads( better a
number slightly bigger than your number of CPUs) and let all these
threads wait on IOCP using GetQueuedCompletionStatus(). When a task is
to be done, queue a request to IOCP using
PostQueuedCompletionStatus(). On this one thread from the pool will
wake up from wait and you can do the job there. You would have to
device an appropriate data structure to queue requests.

Fellow MVP Dr. Newcomer has some excelent article on IOCP in his site.
http://www.flounder.com/mvp_tips.htm
Jack
2010-04-22 12:29:36 UTC
Permalink
Hi Faisal,
Lots of thanks for the links. Now I am digging into them....
Jack

Loading...