📄 combine.shar
字号:
fi
fi
# ============= page06.pre ==============
if test -f 'page06.pre' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'page06.pre' '(file already exists)'
else
$echo 'x -' extracting 'page06.pre' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'page06.pre' &&
X
<P><A HREF="client_handler.cpp">client_handler.cpp</A>
shows some of the changes due to the thread-pool. Just a few
though.
X
<P>
<HR WIDTH="100%">
SHAR_EOF
$shar_touch -am 03191459100 'page06.pre' &&
chmod 0664 'page06.pre' ||
$echo 'restore of' 'page06.pre' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'page06.pre:' 'MD5 check failed'
d884389625246dfcd8049f0fc648997d page06.pre
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page06.pre'`"
test 160 -eq "$shar_count" ||
$echo 'page06.pre:' 'original size' '160,' 'current size' "$shar_count!"
fi
fi
# ============= page07.pre ==============
if test -f 'page07.pre' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'page07.pre' '(file already exists)'
else
$echo 'x -' extracting 'page07.pre' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'page07.pre' &&
<P>Two new files this time. The first is <A HREF="thread_pool.h">thread_pool.h</A>
where we declare our Thread_Pool object. This is responsible for
abstracting away the thread pool implementation details and allowing us
to make so few changes to the rest of the code.
X
<P>
<HR WIDTH="100%"><FONT FACE="Arial,Helvetica"></FONT>
X
SHAR_EOF
$shar_touch -am 03191459100 'page07.pre' &&
chmod 0664 'page07.pre' ||
$echo 'restore of' 'page07.pre' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'page07.pre:' 'MD5 check failed'
e5bcf4bee3e756dda50ccb69c18ac3a1 page07.pre
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page07.pre'`"
test 340 -eq "$shar_count" ||
$echo 'page07.pre:' 'original size' '340,' 'current size' "$shar_count!"
fi
fi
# ============= page08.pre ==============
if test -f 'page08.pre' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'page08.pre' '(file already exists)'
else
$echo 'x -' extracting 'page08.pre' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'page08.pre' &&
X
<P>Finally, <A HREF="thread_pool.cpp">thread_pool.cpp</A>
where we have the Thread_Pool object implementation.
<P>
Remember back in <A HREF="../006/page01.html">Tutorial 6</A> when I
X was talking about <i>THR_NEW_LWP</i>? Look closely and you'll
X see it here. It's bitwise OR'd with <i>THR_DETACHED</i> just to
X keep things interesting.
<P>
<HR WIDTH="100%">
SHAR_EOF
$shar_touch -am 03191459100 'page08.pre' &&
chmod 0664 'page08.pre' ||
$echo 'restore of' 'page08.pre' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'page08.pre:' 'MD5 check failed'
09c4d5adcd767080e64649a01bd0957c page08.pre
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page08.pre'`"
test 377 -eq "$shar_count" ||
$echo 'page08.pre:' 'original size' '377,' 'current size' "$shar_count!"
fi
fi
# ============= page09.pre ==============
if test -f 'page09.pre' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'page09.pre' '(file already exists)'
else
$echo 'x -' extracting 'page09.pre' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'page09.pre' &&
X
<P>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.
X
<P>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.
X
<P>For reference, here's the file list again:
<UL>
<LI>
<A HREF="Makefile">Makefile</A></LI>
X
<LI>
<A HREF="client_acceptor.h">client_acceptor.h</A></LI>
X
<LI>
<A HREF="client_acceptor.cpp">client_acceptor.cpp</A></LI>
X
<LI>
<A HREF="client_handler.cpp">client_handler.cpp</A></LI>
X
<LI>
<A HREF="client_handler.h">client_handler.h</A></LI>
X
<LI>
<A HREF="server.cpp">server.cpp</A></LI>
X
<LI>
<A HREF="thread_pool.h">thread_pool.h</A></LI>
X
<LI>
<A HREF="thread_pool.cpp">thread_pool.cpp</A></LI>
X
</UL>
<P>
<HR WIDTH="100%">
<P>
<center><h2>Danger, Warning!</h2></center>
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 <i>after</i> it has been deleted. When the thread's svc()
method attempts to invoke <i>handle_input()</i> you will get a nasty
core dump.
<p>
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.
<p>
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.
SHAR_EOF
$shar_touch -am 03191459100 'page09.pre' &&
chmod 0664 'page09.pre' ||
$echo 'restore of' 'page09.pre' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'page09.pre:' 'MD5 check failed'
8649089f4b28456c033dede0e32276a8 page09.pre
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page09.pre'`"
test 2070 -eq "$shar_count" ||
$echo 'page09.pre:' 'original size' '2070,' 'current size' "$shar_count!"
fi
fi
# ============= page02.pst ==============
if test -f 'page02.pst' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'page02.pst' '(file already exists)'
else
$echo 'x -' extracting 'page02.pst' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'page02.pst' &&
<HR WIDTH="100%">
X
<P>Hmmm... No change there. Maybe I should leave out comments
on the stuff I don't change. Let's take a look at client_acceptor.h.
X
<P>
SHAR_EOF
$shar_touch -am 03191459100 'page02.pst' &&
chmod 0664 'page02.pst' ||
$echo 'restore of' 'page02.pst' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'page02.pst:' 'MD5 check failed'
b6226123f4f50eeb16db2f7675aaa171 page02.pst
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page02.pst'`"
test 173 -eq "$shar_count" ||
$echo 'page02.pst:' 'original size' '173,' 'current size' "$shar_count!"
fi
fi
# ============= page03.pst ==============
if test -f 'page03.pst' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'page03.pst' '(file already exists)'
else
$echo 'x -' extracting 'page03.pst' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'page03.pst' &&
<HR WIDTH="100%">
X
<P>Well, except for the new Thread_Pool member variable, most of the changes
are informational.
X
SHAR_EOF
$shar_touch -am 03191459100 'page03.pst' &&
chmod 0664 'page03.pst' ||
$echo 'restore of' 'page03.pst' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'page03.pst:' 'MD5 check failed'
88a4cc7d635a4a6b7645011be580808f page03.pst
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page03.pst'`"
test 116 -eq "$shar_count" ||
$echo 'page03.pst:' 'original size' '116,' 'current size' "$shar_count!"
fi
fi
# ============= page04.pst ==============
if test -f 'page04.pst' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'page04.pst' '(file already exists)'
else
$echo 'x -' extracting 'page04.pst' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'page04.pst' &&
<HR WIDTH="100%">
X
<P>Nothing really surprising here. Most of it just manages the Thread_Pool.
X
<P>
SHAR_EOF
$shar_touch -am 03191459100 'page04.pst' &&
chmod 0664 'page04.pst' ||
$echo 'restore of' 'page04.pst' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'page04.pst:' 'MD5 check failed'
57acbd600df965b4dc96ef0ad7ea9390 page04.pst
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page04.pst'`"
test 106 -eq "$shar_count" ||
$echo 'page04.pst:' 'original size' '106,' 'current size' "$shar_count!"
fi
fi
# ============= page05.pst ==============
if test -f 'page05.pst' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'page05.pst' '(file already exists)'
else
$echo 'x -' extracting 'page05.pst' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'page05.pst' &&
<HR WIDTH="100%">
X
<P>Still, we're just not seeing a lot of changes due to introduction of
the thread pool. That's a good thing! You don't want to go turning
your application upside down just because you changed thread models.
X
SHAR_EOF
$shar_touch -am 03191459100 'page05.pst' &&
chmod 0664 'page05.pst' ||
$echo 'restore of' 'page05.pst' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'page05.pst:' 'MD5 check failed'
98cba63a4dffe925484ca86368c863bb page05.pst
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page05.pst'`"
test 234 -eq "$shar_count" ||
$echo 'page05.pst:' 'original size' '234,' 'current size' "$shar_count!"
fi
fi
# ============= page06.pst ==============
if test -f 'page06.pst' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'page06.pst' '(file already exists)'
else
$echo 'x -' extracting 'page06.pst' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'page06.pst' &&
<HR WIDTH="100%">
X
<P>Ok, now we've gone and changed handle_input() so that it knows when
to do work and when to enqueue itself. Beyond that, we're still about
the same.
X
SHAR_EOF
$shar_touch -am 03191459100 'page06.pst' &&
chmod 0664 'page06.pst' ||
$echo 'restore of' 'page06.pst' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'page06.pst:' 'MD5 check failed'
bfbc05b1679c397403e7106ef12065d9 page06.pst
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page06.pst'`"
test 177 -eq "$shar_count" ||
$echo 'page06.pst:' 'original size' '177,' 'current size' "$shar_count!"
fi
fi
# ============= page07.pst ==============
if test -f 'page07.pst' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'page07.pst' '(file already exists)'
else
$echo 'x -' extracting 'page07.pst' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'page07.pst' &&
<HR WIDTH="100%">
X
<P>Well, that doesn't look too complex. What about the implementation?
X
SHAR_EOF
$shar_touch -am 03191459100 'page07.pst' &&
chmod 0664 'page07.pst' ||
$echo 'restore of' 'page07.pst' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'page07.pst:' 'MD5 check failed'
c1a7fbfe20f12e5a8bdeccc7c8e1af1c page07.pst
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page07.pst'`"
test 97 -eq "$shar_count" ||
$echo 'page07.pst:' 'original size' '97,' 'current size' "$shar_count!"
fi
fi
rm -fr _sh32447
exit 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -