📄 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/018'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 416 -rw-rw-r-- hdr
# 64 -rw-rw-r-- bodies
# 2586 -rw-rw-r-- page01.pre
# 430 -rw-rw-r-- page02.pre
# 1279 -rw-rw-r-- page03.pre
# 688 -rw-rw-r-- page04.pre
# 259 -rw-rw-r-- page05.pre
# 1519 -rw-rw-r-- page06.pre
# 476 -rw-rw-r-- page07.pre
#
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 _sh00359; 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="Author" CONTENT="James CE Johnson">
X <TITLE>ACE Tutorial 018</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#000FFF" VLINK="#FF0F0F">
X
<CENTER><B><FONT SIZE=+2>ACE Tutorial 018</FONT></B></CENTER>
X
<CENTER><B><FONT SIZE=+2>The FIFO Nature of ACE_Token</FONT></B></CENTER>
X
<P>
<HR WIDTH="100%">
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'
66dbcd27e23cdcc9c230089e9c289bcb hdr
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'hdr'`"
test 416 -eq "$shar_count" ||
$echo 'hdr:' 'original size' '416,' '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
token.cpp
Test_T.h
Test_T.cpp
Token_i.h Mutex_i.h
output
SHAR_EOF
$shar_touch -am 1114165298 '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'
22e70b25b6f23655b44d31fcf1a669f8 bodies
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'bodies'`"
test 64 -eq "$shar_count" ||
$echo 'bodies:' 'original size' '64,' '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
Welcome to Tutorial 18!
<P>
We've seen various ACE methods for synchronization in this and other
tutorial sections. Something we haven't yet seen is the ACE_Token.
ACE_Token has a really cool thing: it behaves in a FIFO manner.
<P>
Why is that cool?
<P>
In the other tutorials, you may have found that one thread will end up
with all of the work. Even though other threads are available, the OS
scheduling and lock management just causes it to happen. With
ACE_Token, the threads are queued up on the token and served in a
traditional first-in-first-out manner.
<P>
Why is FIFO important?
<P>
Well, if your app is running in a bunch of threads and each is doing
the same thing on the local host then FIFO may not be important.
However, take the case where each thread is connected to a remote
system. Let's say you have a dozen threads in your app and each is
connected to a different remote system. Each of the threads will be
given a block of data which will be passed to the remote for some
intense calculation. If you use the FIFO then you'll spread the work
more-or-less evenly between the remote peers. If you use the
traditional mutex then one peer may get the lion's share of the work.
<P>
It gets down to a personal decision based on the application's needs.
Consider your application, examine its behavior & decide for yourself
if you want to spread the work evenly or if it's OK to let some
threads work harder than others.
<P>
Kirthika's abstract:
<UL>
A token is similar to a mutex-lock, with the difference being that
the token is given to the waiting threads in a FIFO order. In the case
of the mutex-lock, any thread (depending on the OS) could acquire
the lock when its released. It internally implements a recursive mutex,
i.e. the thread that owns the mutex can reqacquire it without deadlocking.
The token also has two FIFO lists for writers and readers with writer-
acquires having a higher priority than reader-acquires.
<P>
This tutorial throws light on the differences on having a shared resource governed by
a lock and a token, both derive from a Task which simply updates a counter with the
number-of-threads value. A barrier is used for ensuring that all threads get a equal
opportunity of grabbing the token. The message queue with the message containing the
thread count moves among the threads to be obtained and read.
<P>
On obtaining the results, we conclude that on using the Token, the job to be completed
can be distributed evenly among available threads. This cant be guaranteed
in case of simply using the lock for synchronisation.
</ul>
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'
c2c450403d3a23fb5c1d2f1dc23a1eb4 page01.pre
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page01.pre'`"
test 2586 -eq "$shar_count" ||
$echo 'page01.pre:' 'original size' '2586,' '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' &&
Our main() just keeps getting simpler! I guess that's a good thing.
<P>
What we've done is create two Task-derived objects that test different
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -