diff options
Diffstat (limited to 'docs/tutorials/007/page08.html')
-rw-r--r-- | docs/tutorials/007/page08.html | 64 |
1 files changed, 46 insertions, 18 deletions
diff --git a/docs/tutorials/007/page08.html b/docs/tutorials/007/page08.html index 5c3ede6e8ab..094804e743d 100644 --- a/docs/tutorials/007/page08.html +++ b/docs/tutorials/007/page08.html @@ -16,14 +16,14 @@ <P> <HR WIDTH="100%"> -<P>Finally, <A HREF="thread_pool.cpp">thread_pool.cpp</A> where we have -the Thread_Pool object implementation. +<P>Finally, <A HREF="thread_pool.cpp">thread_pool.cpp</A> +where we have the Thread_Pool object implementation. <P> -<HR WIDTH="100%"><FONT FACE="Arial,Helvetica"></FONT> +<HR WIDTH="100%"> <P><FONT FACE="Arial,Helvetica">// $Id: thread_pool.cpp,v 1.1 1998/08/30 -16:04:12 jcej Exp $</FONT><FONT FACE="Arial,Helvetica"></FONT> +23:47:15 schmidt Exp $</FONT><FONT FACE="Arial,Helvetica"></FONT> <P><FONT FACE="Arial,Helvetica">#include "thread_pool.h"</FONT><FONT FACE="Arial,Helvetica"></FONT> @@ -164,9 +164,9 @@ to be very clear about what we're doing.</FONT><FONT FACE="Arial,Helvetica"></FO <P><FONT FACE="Arial,Helvetica"> First: Cast the handler pointer to a void pointer. You can't do any useful work</FONT> -<BR><FONT FACE="Arial,Helvetica"> +<BR><FONT FACE="Arial,Helvetica"> on a void pointer, so this is a clear message that we're making the</FONT> -<BR><FONT FACE="Arial,Helvetica"> +<BR><FONT FACE="Arial,Helvetica"> pointer unusable.</FONT><FONT FACE="Arial,Helvetica"></FONT> <P><FONT FACE="Arial,Helvetica"> @@ -211,16 +211,16 @@ if( this->putq(mb) == -1 )</FONT> <BR><FONT FACE="Arial,Helvetica"> Another trait of the ACE_Message_Block objects is that they are reference counted.</FONT> -<BR><FONT FACE="Arial,Helvetica"> +<BR><FONT FACE="Arial,Helvetica"> Since they're designed to be passed around between various objects in several threads</FONT> -<BR><FONT FACE="Arial,Helvetica"> +<BR><FONT FACE="Arial,Helvetica"> we can't just delete them whenever we feel like it. The release() method is similar</FONT> -<BR><FONT FACE="Arial,Helvetica"> +<BR><FONT FACE="Arial,Helvetica"> to the destroy() method we've used elsewhere. It watches the reference count and will</FONT> -<BR><FONT FACE="Arial,Helvetica"> +<BR><FONT FACE="Arial,Helvetica"> delete the object when possible.</FONT> <BR><FONT FACE="Arial,Helvetica"> */</FONT> @@ -426,18 +426,18 @@ ACE_Event_Handler* but then folks might think that's an OK thing to do.</FONT><F <P><FONT FACE="Arial,Helvetica"> (Note: The correct way to use an ACE_Message_Block is to write data into it.</FONT> -<BR><FONT FACE="Arial,Helvetica"> +<BR><FONT FACE="Arial,Helvetica"> What I should have done was create a message block big enough to hold an</FONT> -<BR><FONT FACE="Arial,Helvetica"> +<BR><FONT FACE="Arial,Helvetica"> event handler pointer and then written the pointer value into the block. When</FONT> -<BR><FONT FACE="Arial,Helvetica"> +<BR><FONT FACE="Arial,Helvetica"> we got here, I would have to read that data back into a pointer. While politically</FONT> -<BR><FONT FACE="Arial,Helvetica"> +<BR><FONT FACE="Arial,Helvetica"> correct, it is also a lot of work. If you're careful you can get away with casting</FONT> -<BR><FONT FACE="Arial,Helvetica"> +<BR><FONT FACE="Arial,Helvetica"> pointers around.)</FONT> <BR><FONT FACE="Arial,Helvetica"> */</FONT> @@ -464,7 +464,35 @@ if( handler->handle_input(ACE_INVALID_HANDLE) == -1 )</FONT> <BR><FONT FACE="Arial,Helvetica"> {</FONT> <BR><FONT FACE="Arial,Helvetica"> -return(-1); // Error, return now</FONT> +/*</FONT> +<BR><FONT FACE="Arial,Helvetica"> +Tell the handler that it's time to go home. The "normal" method for +shutting</FONT> +<BR><FONT FACE="Arial,Helvetica"> +down a handler whose handler failed is to invoke handle_close(). +This will</FONT> +<BR><FONT FACE="Arial,Helvetica"> +take care of cleaning it up for us.</FONT> +<BR><FONT FACE="Arial,Helvetica"> +Notice how we use the handler's get_handle() method to populate it's "handle"</FONT> +<BR><FONT FACE="Arial,Helvetica"> +parameter. Convenient isn't it?</FONT> +<BR><FONT FACE="Arial,Helvetica"> +*/</FONT> +<BR><FONT FACE="Arial,Helvetica"> +handler->handle_close(handler->get_handle(),0);</FONT><FONT FACE="Arial,Helvetica"></FONT> + +<P><FONT FACE="Arial,Helvetica"> +/*</FONT> +<BR><FONT FACE="Arial,Helvetica"> +Also notice that we don't exit the svc() method here! The first time +I did</FONT> +<BR><FONT FACE="Arial,Helvetica"> +this, I was exiting. After a few clients disconnect you have an empty</FONT> +<BR><FONT FACE="Arial,Helvetica"> +thread pool. Hard to do any more work after that...</FONT> +<BR><FONT FACE="Arial,Helvetica"> +*/</FONT> <BR><FONT FACE="Arial,Helvetica"> }</FONT> <BR><FONT FACE="Arial,Helvetica"> @@ -498,11 +526,11 @@ return(0); &nbs <P><FONT FACE="Arial,Helvetica"> return(0);</FONT> <BR><FONT FACE="Arial,Helvetica">}</FONT> -<BR><FONT FACE="Arial,Helvetica"></FONT> <FONT FACE="Arial,Helvetica"></FONT> <P> <HR WIDTH="100%"> -<CENTER>[<A HREF="..">Tutorial Index</A>] [<A HREF="page09.html">Continue +<CENTER>[<A HREF="..">Tutorial +Index</A>] [<A HREF="page09.html">Continue This Tutorial</A>]</CENTER> </BODY> |