📄 combine.shar
字号:
<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'
4fe23822fef63921fa81cbf97e25bd5e page04.pre
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page04.pre'`"
test 127 -eq "$shar_count" ||
$echo 'page04.pre:' 'original size' '127,' '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
Let's take a look at this new program's output:
X
<P>
<HR WIDTH="100%">
<PRE>
[jcej@chiroptera 011]$./message_queue 4 2
(12108|1024) Task ctor 0xbffff9c8
(12108|2050) Task 0xbffff9c8 starts in thread 2050
(12108|1025) Task 0xbffff9c8 starts in thread 1025
(12108|1024) DataBase ctor 0xbffff9c0
(12108|1024) Data ctor 0xbffff9c0 for message 0
(12108|1024) Block ctor 0x8052d08
(12108|1024) Data dtor 0xbffff9c0
(12108|1024) DataBase dtor 0xbffff9c0
(12108|1024) DataBase ctor 0xbffff9c0
(12108|1024) Data ctor 0xbffff9c0 for message 1
(12108|1024) Block ctor 0x8052e00
(12108|1024) Data dtor 0xbffff9c0
(12108|1024) DataBase dtor 0xbffff9c0
(12108|1024) DataBase ctor 0xbffff9c0
(12108|1024) Data ctor 0xbffff9c0 for message 2
(12108|1024) Block ctor 0x8052ef8
(12108|1024) Data dtor 0xbffff9c0
(12108|1024) DataBase dtor 0xbffff9c0
(12108|1024) DataBase ctor 0xbffff9c0
(12108|1024) Data ctor 0xbffff9c0 for message 3
(12108|1024) Block ctor 0x8052ff0
(12108|1024) Data dtor 0xbffff9c0
(12108|1024) DataBase dtor 0xbffff9c0
(12108|1024) Block ctor 0x80530e8
(12108|1025) Block 0x8052d08 contains (This is message 0.)
(12108|1025) DataBase ctor 0xbf9ffe20
(12108|1025) Data ctor 0xbf9ffe20
(12108|1025) DataBase instance 0xbf9ffe20
(12108|1025) I am a Data object for message 0
(12108|1025) Block dtor 0x8052d08
(12108|1025) Data dtor 0xbf9ffe20
(12108|1025) DataBase dtor 0xbf9ffe20
(12108|1025) Block 0x8052e00 contains (This is message 1.)
(12108|1025) DataBase ctor 0xbf9ffe20
(12108|1025) Data ctor 0xbf9ffe20
(12108|1025) DataBase instance 0xbf9ffe20
(12108|1025) I am a Data object for message 1
(12108|1025) Block dtor 0x8052e00
(12108|1025) Data dtor 0xbf9ffe20
(12108|1025) DataBase dtor 0xbf9ffe20
(12108|1025) Block 0x8052ef8 contains (This is message 2.)
(12108|1025) DataBase ctor 0xbf9ffe20
(12108|1025) Data ctor 0xbf9ffe20
(12108|1025) DataBase instance 0xbf9ffe20
(12108|1025) I am a Data object for message 2
(12108|1025) Block dtor 0x8052ef8
(12108|1025) Data dtor 0xbf9ffe20
(12108|1025) DataBase dtor 0xbf9ffe20
(12108|1025) Block 0x8052ff0 contains (This is message 3.)
(12108|1025) DataBase ctor 0xbf9ffe20
(12108|1025) Data ctor 0xbf9ffe20
(12108|1025) DataBase instance 0xbf9ffe20
(12108|1025) I am a Data object for message 3
(12108|2050) Task close 0xbffff9c8
(12108|1025) Block dtor 0x8052ff0
(12108|1025) Data dtor 0xbf9ffe20
(12108|1025) DataBase dtor 0xbf9ffe20
(12108|1025) Task close 0xbffff9c8
(12108|1024) Task dtor 0xbffff9c8
(12108|1024) Block dtor 0x80530e8
(12108|1024) Application exiting
[jcej@chiroptera 011]$
</PRE>
<HR WIDTH="100%">
<P>
Other than being more verbose because of the Data object, this shows us
the same thing we've seen before.
<P>
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'
b95ed571240b8383db0e0c0b07d04971 page05.pre
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page05.pre'`"
test 2691 -eq "$shar_count" ||
$echo 'page05.pre:' 'original size' '2691,' 'current size' "$shar_count!"
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' &&
So, this time we stuffed an object into the message queue instead of just text
data. Each time required two object constructions (and subsequent destructions)
and two "deep" copy operations on the object. There might actually be times when
this is OK for your application but I prefer to keep those things down to a
minimum. In the next tutorial I'll show you a way to do that.
<P>
X
<UL>
<LI><A HREF="Makefile">Makefile</A>
<LI><A HREF="block.h">block.h</A>
<LI><A HREF="data.h">data.h</A>*
<LI><A HREF="message_queue.cpp">message_queue.cpp</A>
<LI><A HREF="task.cpp">task.cpp</A>
<LI><A HREF="task.h">task.h</A>
</UL>
X
* data.h hasn't changed at all from Tutorial 7 so I didn't devote a
X page to it.
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'
17d64bbe275773a80d7d767e04e0474c page06.pre
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page06.pre'`"
test 707 -eq "$shar_count" ||
$echo 'page06.pre:' 'original size' '707,' '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%">
<P>
The new trick here is the use of copy() to copy our abstract data object
into the message block memory. Notice that it's OK to let the Data object
go out of scope at that point since we've got a separate copy. If you've
got something with a non-trivial ctor/dtor then this won't work. We'll address
that in the next tutorial.
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'
89fa13e74842bc65092e0e6f61fdd889 page02.pst
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page02.pst'`"
test 351 -eq "$shar_count" ||
$echo 'page02.pst:' 'original size' '351,' '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%">
<P>
Notice how we had to create a temporary Data object to copy the stuff out
of the message block? Again, if there were non-trivial ctor/dtors involved
then this wouldn't work at all.
<P>
Again, like <A HREF="../010/page01.html">Tutorial 10</A> we've skipped
<i>THR_DETACHED</i> because we <i>wait()</i> for the threads to exit
X elsewhere.
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'
1005245771b0756716fa87dfdf966155 page03.pst
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page03.pst'`"
test 365 -eq "$shar_count" ||
$echo 'page03.pst:' 'original size' '365,' '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%">
<P>
Ok, no mysterious magic on this one. Just a simple object and derivative
that report their existence.
<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'
777ab8789fb82b1e280b9e127983c4b0 page04.pst
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page04.pst'`"
test 129 -eq "$shar_count" ||
$echo 'page04.pst:' 'original size' '129,' 'current size' "$shar_count!"
fi
fi
rm -fr _sh32588
exit 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -