📄 combine.shar
字号:
#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.2).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 2000-03-19 15:00 EST by <jcej@chiroptera.tragus.org>.
# Source directory was `/home/jcej/projects/ACE_wrappers/docs/tutorials/007'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 576 -rw-rw-r-- hdr
# 123 -rw-rw-r-- bodies
# 3383 -rw-rw-r-- page01.pre
# 87 -rw-rw-r-- page02.pre
# 120 -rw-rw-r-- page03.pre
# 171 -rw-rw-r-- page04.pre
# 105 -rw-rw-r-- page05.pre
# 160 -rw-rw-r-- page06.pre
# 340 -rw-rw-r-- page07.pre
# 377 -rw-rw-r-- page08.pre
# 2070 -rw-rw-r-- page09.pre
# 173 -rw-rw-r-- page02.pst
# 116 -rw-rw-r-- page03.pst
# 106 -rw-rw-r-- page04.pst
# 234 -rw-rw-r-- page05.pst
# 177 -rw-rw-r-- page06.pst
# 97 -rw-rw-r-- page07.pst
#
save_IFS="${IFS}"
IFS="${IFS}:"
gettext_dir=FAILED
locale_dir=FAILED
first_param="$1"
for dir in $PATH
do
if test "$gettext_dir" = FAILED && test -f $dir/gettext \
&& ($dir/gettext --version >/dev/null 2>&1)
then
set `$dir/gettext --version 2>&1`
if test "$3" = GNU
then
gettext_dir=$dir
fi
fi
if test "$locale_dir" = FAILED && test -f $dir/shar \
&& ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
then
locale_dir=`$dir/shar --print-text-domain-dir`
fi
done
IFS="$save_IFS"
if test "$locale_dir" = FAILED || test "$gettext_dir" = FAILED
then
echo=echo
else
TEXTDOMAINDIR=$locale_dir
export TEXTDOMAINDIR
TEXTDOMAIN=sharutils
export TEXTDOMAIN
echo="$gettext_dir/gettext -s"
fi
touch -am 1231235999 $$.touch >/dev/null 2>&1
if test ! -f 1231235999 && test -f $$.touch; then
shar_touch=touch
else
shar_touch=:
echo
$echo 'WARNING: not restoring timestamps. Consider getting and'
$echo "installing GNU \`touch', distributed in GNU File Utilities..."
echo
fi
rm -f 1231235999 $$.touch
#
if mkdir _sh32447; then
$echo 'x -' 'creating lock directory'
else
$echo 'failed to create lock directory'
exit 1
fi
# ============= hdr ==============
if test -f 'hdr' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'hdr' '(file already exists)'
else
$echo 'x -' extracting 'hdr' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'hdr' &&
<HTML>
<HEAD>
X <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
X <META NAME="GENERATOR" CONTENT="Mozilla/4.04 [en] (X11; I; Linux 2.0.32 i486) [Netscape]">
X <META NAME="Author" CONTENT="James CE Johnson">
X <META NAME="Description" CONTENT="A first step towards using ACE productively">
X <TITLE>ACE Tutorial 007</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#000FFF" VLINK="#FF0F0F">
X
<CENTER><B><FONT SIZE=+2>ACE Tutorial 007</FONT></B></CENTER>
X
<CENTER><B><FONT SIZE=+2>Creating a thread-pool server</FONT></B></CENTER>
<HR>
SHAR_EOF
$shar_touch -am 03191459100 'hdr' &&
chmod 0664 'hdr' ||
$echo 'restore of' 'hdr' '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 'hdr:' 'MD5 check failed'
151b1b4bda96cc1e3ef55356e819ca42 hdr
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'hdr'`"
test 576 -eq "$shar_count" ||
$echo 'hdr:' 'original size' '576,' 'current size' "$shar_count!"
fi
fi
# ============= bodies ==============
if test -f 'bodies' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'bodies' '(file already exists)'
else
$echo 'x -' extracting 'bodies' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'bodies' &&
PAGE=2
server.cpp
client_acceptor.h
client_acceptor.cpp
client_handler.h
client_handler.cpp
thread_pool.h
thread_pool.cpp
X
SHAR_EOF
$shar_touch -am 0121152599 'bodies' &&
chmod 0664 'bodies' ||
$echo 'restore of' 'bodies' '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 'bodies:' 'MD5 check failed'
7675a97fa145886f534c43a8e1a0e6d1 bodies
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'bodies'`"
test 123 -eq "$shar_count" ||
$echo 'bodies:' 'original size' '123,' 'current size' "$shar_count!"
fi
fi
# ============= page01.pre ==============
if test -f 'page01.pre' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'page01.pre' '(file already exists)'
else
$echo 'x -' extracting 'page01.pre' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'page01.pre' &&
X
X
X
<P>In this tutorial, we're going to extend Tutorial 6 to add a third concurrency
strategy: thread-pool. Like Tutorial 6 did to Tutorial 5, we're
going to keep the existing strategies that we've already created and add
this one in as a "bonus". As you'll see, our basic objects will change
but not by a whole lot. To accomplish this, we'll introduce one new
major object that helps to abstract the thread pool concept.
<P>
Some folks have noted that this tutorial is a bit confusing if you
don't first know about ACE_Task. My advice is to give it all a good
read a couple of times. If you're still having problems, take a look
at the ACE_Task tests in $ACE_ROOT/tests or examples in $ACE_ROOT/examples.
<P>
Kirthika's Abstract:
<UL>
In this multithreaded server, the Client_Acceptor has the additional
strategy of managing a thread pool. This helps when two clients don't
want to share the same resources or when different clients
need to run in different priority threads. We could then pool all the
same priority clients into one thread-pool. The thread_pool class is a
new addition used to implement this strategy. It inherits from ACE_Task
with ACE_MT_SYNCH parameter which takes care of syncronization issues
amongst multiple threads.
<P>
ACE_Task follows the Active Object pattern and executes the methods on
the task object in a new thread of execution, i.e it decouples the
execution of a method from its invocation. An ACE_Task has an underlying
thread (or pool of threads) and a Message_Queue which is the only means
of communication among tasks. A Message_Queue consists of
Message_Blocks.
<P>
The Client_Acceptor is registered with the reactor waiting for
connection requests.
On some activity, the reactor calls the handle_input() method on the
Acceptor. The Client_Handler of the Acceptor (for the thread-pool
strategy) unregisters itself from the reactor and
enqueues itself in the Message_Queue of the thread-pool waiting for
svc() to call handle_input() on it. It would then process the data in
its new thread of execution. The ACE_MT_SYNCH option facilitates access
of the Mesage_Blocks across different Message_Queues (here from the main
thread to the one in the thread pool).
<P>
The thread_pool class derives from the ACE_Task class. Its svc() method
dequeues the threads in the Message_Queue and calls handle_input() on
them. The idle threads can take work from the queue while the other
threads are working. It also uses ACE_Atomic_Op as a counter for active
threads in the pool. Also, the ACE_Guard class has been used to provide
thread-safe counter-incrementation and destruction of the Message_Blocks
of the thread-pool. This class guards the critical section region by
acquiring the mutex lock on creation and releasing it as soon as it goes
out of scope.
<P>
Note: a sleep period before all the threads in the pool exit is
necessary for complete destruction of the thread pool.
<P>
This tutorial gives us a flavour of implementing a server with a
thread-pool strategy and how it can be managed using the ACE_Task class,
which provides an OO approach to thread-creation and implementation.
</UL>
<font size=-1>* The additions to this tutorial make use of
ACE_Message_Queue which is discussed in depth in
<A HREF="../010/page01.html">Tutorial 10</A>. Feel free to read ahead
if you get lost in the message queue stuff.
</font>
SHAR_EOF
$shar_touch -am 03191459100 'page01.pre' &&
chmod 0664 'page01.pre' ||
$echo 'restore of' 'page01.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 'page01.pre:' 'MD5 check failed'
0bd3a7ce4fbd16691109b32892c3a864 page01.pre
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page01.pre'`"
test 3383 -eq "$shar_count" ||
$echo 'page01.pre:' 'original size' '3383,' 'current size' "$shar_count!"
fi
fi
# ============= page02.pre ==============
if test -f 'page02.pre' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'page02.pre' '(file already exists)'
else
$echo 'x -' extracting 'page02.pre' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'page02.pre' &&
<P>As usualy, we start with <A HREF="server.cpp">server.cpp</A>
<BR>
<HR WIDTH="100%">
SHAR_EOF
$shar_touch -am 03191459100 'page02.pre' &&
chmod 0664 'page02.pre' ||
$echo 'restore of' 'page02.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 'page02.pre:' 'MD5 check failed'
37639524942e8882c94523e5189b22ff page02.pre
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page02.pre'`"
test 87 -eq "$shar_count" ||
$echo 'page02.pre:' 'original size' '87,' 'current size' "$shar_count!"
fi
fi
# ============= page03.pre ==============
if test -f 'page03.pre' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'page03.pre' '(file already exists)'
else
$echo 'x -' extracting 'page03.pre' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'page03.pre' &&
X
<P>Let's see what things we've had to add to <A HREF="client_acceptor.h">client_acceptor.h</A>.
X
<P>
<HR WIDTH="100%">
SHAR_EOF
$shar_touch -am 03191459100 'page03.pre' &&
chmod 0664 'page03.pre' ||
$echo 'restore of' 'page03.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 'page03.pre:' 'MD5 check failed'
64592ded5ea700b4147face8ad77018f page03.pre
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page03.pre'`"
test 120 -eq "$shar_count" ||
$echo 'page03.pre:' 'original size' '120,' 'current size' "$shar_count!"
fi
fi
# ============= page04.pre ==============
if test -f 'page04.pre' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'page04.pre' '(file already exists)'
else
$echo 'x -' extracting 'page04.pre' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'page04.pre' &&
X
<P>Something new this time is <A HREF="client_acceptor.cpp">client_acceptor.cpp</A>.
I finally had enough code to move it out of the header.
X
<P>
<HR WIDTH="100%">
SHAR_EOF
$shar_touch -am 03191459100 'page04.pre' &&
chmod 0664 'page04.pre' ||
$echo 'restore of' 'page04.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 'page04.pre:' 'MD5 check failed'
d5640eb97c0a746761c946c4e93db2e8 page04.pre
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page04.pre'`"
test 171 -eq "$shar_count" ||
$echo 'page04.pre:' 'original size' '171,' 'current size' "$shar_count!"
fi
fi
# ============= page05.pre ==============
if test -f 'page05.pre' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'page05.pre' '(file already exists)'
else
$echo 'x -' extracting 'page05.pre' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'page05.pre' &&
X
<P>As you might expect, <A HREF="client_handler.h">client_handler.h</A>
is next.
X
<P>
<HR WIDTH="100%">
SHAR_EOF
$shar_touch -am 03191459100 'page05.pre' &&
chmod 0664 'page05.pre' ||
$echo 'restore of' 'page05.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 'page05.pre:' 'MD5 check failed'
e882d389de5d95571737cfc58552153a page05.pre
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page05.pre'`"
test 105 -eq "$shar_count" ||
$echo 'page05.pre:' 'original size' '105,' 'current size' "$shar_count!"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -