ACE Tutorial 007
Creating a thread-pool server

That's it for Tutorial 7.  As with Tutorial 6, we really didn't have to change much to introduce a new threading strategy.  Most of the work was in creating the Thread_Pool object itself.  Everything else was just minor housekeeping.

There is a fourth common thread strategy:  thread-per-request.  It's not one of my favorites, so I wasn't planning to go into it.  If you want to contribute a tutorial on that topic though, I'll be glad to include it here.

For reference, here's the file list again:


Danger, Warning!

Now that I've gone through all of this to create a thread pool server, I have to point out that this isn't exactly the best or safest way to do so. The biggest danger we face with this approach is the possibility of an event handler existing in the thread pool's message queue after it has been deleted. When the thread's svc() method attempts to invoke handle_input() you will get a nasty core dump.

The safest way to handle the situation is to use reference-counted pointers everywhere a Client_Handler pointer would be used. That's beyond the scope of the tutorial but I encourage you to give it a try. If you want to contribute that back as an enhanced Tutorial, I'll be glad to include it.

Another approach that should work quite well is to use the ACE_TP_Reactor instead of just ACE_Reactor. This takes a little more setup but results in a cleaner implementation. Again, I've not had time to develop a Tutorial on the TP_Reactor but would welcome any contributions.


[Tutorial Index]