diff options
Diffstat (limited to 'docs/tutorials/010')
-rw-r--r-- | docs/tutorials/010/010.dsp | 112 | ||||
-rw-r--r-- | docs/tutorials/010/Makefile | 73 | ||||
-rw-r--r-- | docs/tutorials/010/block.h | 42 | ||||
-rw-r--r-- | docs/tutorials/010/combine.shar | 545 | ||||
-rw-r--r-- | docs/tutorials/010/message_queue.cpp | 88 | ||||
-rw-r--r-- | docs/tutorials/010/page01.html | 60 | ||||
-rw-r--r-- | docs/tutorials/010/page02.html | 125 | ||||
-rw-r--r-- | docs/tutorials/010/page03.html | 73 | ||||
-rw-r--r-- | docs/tutorials/010/page04.html | 76 | ||||
-rw-r--r-- | docs/tutorials/010/page05.html | 164 | ||||
-rw-r--r-- | docs/tutorials/010/page06.html | 56 | ||||
-rw-r--r-- | docs/tutorials/010/page07.html | 30 | ||||
-rw-r--r-- | docs/tutorials/010/task.cpp | 123 | ||||
-rw-r--r-- | docs/tutorials/010/task.h | 45 |
14 files changed, 0 insertions, 1612 deletions
diff --git a/docs/tutorials/010/010.dsp b/docs/tutorials/010/010.dsp deleted file mode 100644 index 85a15e7585a..00000000000 --- a/docs/tutorials/010/010.dsp +++ /dev/null @@ -1,112 +0,0 @@ -# Microsoft Developer Studio Project File - Name="010" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Console Application" 0x0103
-
-CFG=010 - Win32 Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "010.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "010.mak" CFG="010 - Win32 Debug"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "010 - Win32 Release" (based on "Win32 (x86) Console Application")
-!MESSAGE "010 - Win32 Debug" (based on "Win32 (x86) Console Application")
-!MESSAGE
-
-# Begin Project
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "010 - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release"
-# PROP Intermediate_Dir "Release"
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\.." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
-# ADD LINK32 ace.lib /nologo /subsystem:console /machine:I386 /libpath:"..\..\..\ace"
-
-!ELSEIF "$(CFG)" == "010 - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug"
-# PROP BASE Intermediate_Dir "Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Debug"
-# PROP Intermediate_Dir "Debug"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /GX /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD CPP /nologo /MDd /W3 /GX /Od /I "..\..\.." /D "WIN32" /D "_DEBUG" /YX /FD /c
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 aced.lib /nologo /subsystem:console /debug /machine:I386 /out:"message_queue.exe" /pdbtype:sept /libpath:"..\..\..\ace"
-
-!ENDIF
-
-# Begin Target
-
-# Name "010 - Win32 Release"
-# Name "010 - Win32 Debug"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=.\message_queue.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\task.cpp
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# Begin Source File
-
-SOURCE=.\block.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\task.h
-# End Source File
-# End Group
-# Begin Group "Resource Files"
-
-# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
-# End Group
-# End Target
-# End Project
diff --git a/docs/tutorials/010/Makefile b/docs/tutorials/010/Makefile deleted file mode 100644 index 41d9ecfb6bd..00000000000 --- a/docs/tutorials/010/Makefile +++ /dev/null @@ -1,73 +0,0 @@ - -# $Id$ - -#---------------------------------------------------------------------------- -# Local macros -#---------------------------------------------------------------------------- - -BIN = message_queue - -FILES = -FILES += task - -BUILD = $(VBIN) - -SRC = $(addsuffix .cpp,$(BIN)) $(addsuffix .cpp,$(FILES)) - -HDR = *.h - -#---------------------------------------------------------------------------- -# Include macros and targets -#---------------------------------------------------------------------------- - -include $(ACE_ROOT)/include/makeinclude/wrapper_macros.GNU -include $(ACE_ROOT)/include/makeinclude/macros.GNU -include $(ACE_ROOT)/include/makeinclude/rules.common.GNU -include $(ACE_ROOT)/include/makeinclude/rules.nonested.GNU -include $(ACE_ROOT)/include/makeinclude/rules.bin.GNU -include $(ACE_ROOT)/include/makeinclude/rules.local.GNU - -#---------------------------------------------------------------------------- -# Local targets -#---------------------------------------------------------------------------- - -Indent : # - for i in $(SRC) $(HDR) ; do \ - indent -npsl -l80 -fca -fc1 -cli0 -cdb -ts2 -bl -bli0 < $$i | \ - sed -e 's/: :/::/g' \ - -e 's/^.*\(public:\)/\1/' \ - -e 's/^.*\(protected:\)/\1/' \ - -e 's/^.*\(private:\)/\1/' \ - -e 's/:\(public\)/ : \1/' \ - -e 's/:\(protected\)/ : \1/' \ - -e 's/:\(private\)/ : \1/' \ - -e 's/ / /g' \ - > $$i~ ;\ - mv $$i~ $$i ;\ - done - -Depend : depend - perl ../fix.Makefile - -.depend : # - touch .depend - -HTML : # - [ -f hdr ] || $(MAKE) UNSHAR - perl ../combine *.pre ; chmod +r *.html - -SHAR : # - [ ! -f combine.shar ] || exit 1 - shar -T hdr bodies *.pre *.pst > combine.shar && $(RM) hdr bodies *.pre *.pst - -UNSHAR : # - sh combine.shar - -CLEAN : realclean - $(RM) hdr bodies *.pre *.pst .depend - -#---------------------------------------------------------------------------- -# Dependencies -#---------------------------------------------------------------------------- - -include .depend diff --git a/docs/tutorials/010/block.h b/docs/tutorials/010/block.h deleted file mode 100644 index 7288c18724b..00000000000 --- a/docs/tutorials/010/block.h +++ /dev/null @@ -1,42 +0,0 @@ -// $Id$ - -#ifndef BLOCK_H -#define BLOCK_H - -#include "ace/Message_Block.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -/* This simple ACE_Message_Block derivative will inform us of it's - construction and destruction. We'll use this to assure ourselves - that we don't have any memory leaks. In a real application, of - course, this isn't necessary. */ -class Block : public ACE_Message_Block -{ -public: - Block (void) - { - ACE_DEBUG ((LM_DEBUG, - "(%P|%t) Block ctor 0x%x\n", - (void *) this)); - } - - Block (size_t size) - : ACE_Message_Block (size) - { - ACE_DEBUG ((LM_DEBUG, - "(%P|%t) Block ctor 0x%x\n", - (void *) this)); - } - - virtual ~Block (void) - { - ACE_DEBUG ((LM_DEBUG, - "(%P|%t) Block dtor 0x%x\n", - (void *) this)); - } -}; - -#endif /* BLOCK_H */ diff --git a/docs/tutorials/010/combine.shar b/docs/tutorials/010/combine.shar deleted file mode 100644 index ce6e2a2ef31..00000000000 --- a/docs/tutorials/010/combine.shar +++ /dev/null @@ -1,545 +0,0 @@ -#!/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 1999-02-09 16:27 EST by <jcej@chiroptera.tragus.org>. -# Source directory was `/var/home/jcej/projects/ACE_wrappers/docs/tutorials/010'. -# -# Existing files will *not* be overwritten unless `-c' is specified. -# -# This shar contains: -# length mode name -# ------ ---------- ------------------------------------------ -# 440 -rw-rw-r-- hdr -# 49 -rw-rw-r-- bodies -# 2246 -rw-rw-r-- page01.pre -# 84 -rw-rw-r-- page02.pre -# 231 -rw-rw-r-- page03.pre -# 138 -rw-rw-r-- page04.pre -# 607 -rw-rw-r-- page05.pre -# 1493 -rw-rw-r-- page06.pre -# 444 -rw-rw-r-- page07.pre -# 689 -rw-rw-r-- page02.pst -# 237 -rw-rw-r-- page03.pst -# 387 -rw-rw-r-- page04.pst -# 366 -rw-rw-r-- page05.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 _sh15890; 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 010</TITLE> -</HEAD> -<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#000FFF" VLINK="#FF0F0F"> -X -<CENTER><B><FONT SIZE=+2>ACE Tutorial 010</FONT></B></CENTER> -X -<CENTER><B><FONT SIZE=+2>Passing chunks of data through an ACE_Message_Queue</FONT></B></CENTER> -X -X -<P> -<HR WIDTH="100%"> -SHAR_EOF - $shar_touch -am 0124153399 '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' -e3d97df3787127f8678ec95f024c44c6 hdr -SHAR_EOF - else - shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'hdr'`" - test 440 -eq "$shar_count" || - $echo 'hdr:' 'original size' '440,' '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 -message_queue.cpp -block.h -task.h -task.cpp -SHAR_EOF - $shar_touch -am 0124153399 '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' -888c8b85427980776f703176da1f9ee4 bodies -SHAR_EOF - else - shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'bodies'`" - test 49 -eq "$shar_count" || - $echo 'bodies:' 'original size' '49,' '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' && -<P> -In an earlier tutorial we briefly introduced ACE_Message_Queue. In this -tutorial we'll go into a bit more detail. -<P> -ACE_Message_Queue is modeled after Unix System V IPC mechanisms. The basic -idea is that you put a block of data into one end of the Queue and take it -out of the other end. Your basic FIFO in other words. The SysV mechanism -works great for passing these blocks of data between processes on the same -host but it's a bit overkill for moving blocks between threads. You could -use a pipe, socket or similar mechanism but that still has more overhead than -we really want just for moving data between threads. Process-global memory -is a good technique but then you need a way to signal the "listening" threads. -The ACE_Message_Queue is a better approach: Create blocks of data and enqueue -them in one thread while another thread (or threads) dequeue and perform work. -<P> -Kirthika's Abstract: -<UL> -The Message Queue is a FIFO accessible from multiple threads. -That is, a thread puts the produced blocks of data on the message queue -to be consumed by some other thread/threads and processed. In this -tutorial, we see how effectively the Message Queue in a ACE_Task can be -used to pass data among threads in the thread pool. -(this is very similar to -<A HREF="../007/page01.html">Tutorial 7</A> -X wherein we implemented a -thread-pool server).Here, actual data is passed between the threads and -also an ACE_Barrier has been used to provide synchronisation among -multiple threads. -<P> -The Message Queue consists of Message Blocks, each of which has a read -and write pointer. Using these pointers the message blocks can be -accessed for reading and writing operations. The ACE_Task::svc() method -will put the block onto the queue without bothering about the existence -of a consumer for that block. A thread from the thread pool obtains the -block from the queue, and checks to see whether the block_type is -MB_HANGUP. If so, it puts the block back on the queue for its -peers and exits. Otherwise, it reads the block and processes it before -releasing it. -<P> -This simple tutorial makes us aware of the usage and importance of the -Message Queue which could be used to our advantage especially for -multithreaded applications. -</UL> -SHAR_EOF - $shar_touch -am 0124153899 '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' -84d1b63ff2eb7eecec515b248f73d791 page01.pre -SHAR_EOF - else - shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page01.pre'`" - test 2246 -eq "$shar_count" || - $echo 'page01.pre:' 'original size' '2246,' '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' && -X -We'll look first at <A HREF="message_queue.cpp">main()</A>. -<P> -X -<HR WIDTH="100%"> -SHAR_EOF - $shar_touch -am 0124153399 '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' -166bf09c6c4474767e95ef4a7be20a03 page02.pre -SHAR_EOF - else - shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page02.pre'`" - test 84 -eq "$shar_count" || - $echo 'page02.pre:' 'original size' '84,' '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' && -Our <A HREF="block.h">Block</A> object is a very simple derivative -of the ACE_Message_Block. The only reason I created it was to prove -that the message blocks to, indeed, get freed when we're done with 'em. -<P> -X -<HR WIDTH="100%"> -SHAR_EOF - $shar_touch -am 0124153399 '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' -3164732c254de8d97fac8fd52071ae32 page03.pre -SHAR_EOF - else - shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page03.pre'`" - test 231 -eq "$shar_count" || - $echo 'page03.pre:' 'original size' '231,' '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' && -Our <A HREF="task.h">Task</A> object executes in one or more threads -and reads from the message queue it contains. -<P> -X -<HR WIDTH="100%"> -SHAR_EOF - $shar_touch -am 0124153399 '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' -fec9a7b5b9b2a8f61c0178aaf1b78a91 page04.pre -SHAR_EOF - else - shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page04.pre'`" - test 138 -eq "$shar_count" || - $echo 'page04.pre:' 'original size' '138,' '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 -Our <A HREF="task.cpp">Task</A> object definition. -<P> -Something to look at here is the ACE_Barrier usage. In the -constructor, we tell the barrier how many threads we're using. Then, -in the svc() method, we use the barrier's wait() method. You can -think of the barrier as a semaphore initialized to the thread count. -X Each time wait() -is invoked, the semaphore is decremented and the thread is blocked. -X When the count equals zero, all threads are unblocked and allowed to -continue. -<P> -<font size=-1>Note: This isn't the way ACE_Barrier really works, it's -just an analogy</font> -X -<HR WIDTH="100%"> -SHAR_EOF - $shar_touch -am 0209155699 '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' -ff8f02648de795cd92f08141962d746d page05.pre -SHAR_EOF - else - shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page05.pre'`" - test 607 -eq "$shar_count" || - $echo 'page05.pre:' 'original size' '607,' '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' && -X -Since I added Block just to give us output, let's take a look at that output. -X -<P> -<HR WIDTH="100%"> -<PRE> -[jcej@chiroptera 010]$./message_queue 4 2 -(8910|1024) Task ctor 0xbffff9c4 -(8910|2050) Task 0xbffff9c4 starts in thread 2050 -(8910|1025) Task 0xbffff9c4 starts in thread 1025 -(8910|1024) Block ctor 0x8052398 -(8910|1024) Block ctor 0x8052488 -(8910|1024) Block ctor 0x8052578 -(8910|1024) Block ctor 0x8052668 -(8910|1024) Block ctor 0x8052758 -(8910|1025) Block 0x8052398 contains (This is message 0.) -(8910|2050) Block 0x8052488 contains (This is message 1.) -(8910|1025) Block dtor 0x8052398 -(8910|1025) Block 0x8052578 contains (This is message 2.) -(8910|2050) Block dtor 0x8052488 -(8910|2050) Block 0x8052668 contains (This is message 3.) -(8910|1025) Block dtor 0x8052578 -(8910|1025) Task close 0xbffff9c4 -(8910|2050) Block dtor 0x8052668 -(8910|2050) Task close 0xbffff9c4 -(8910|1024) Task dtor 0xbffff9c4 -(8910|1024) Block dtor 0x8052758 -(8910|1024) Application exiting -[jcej@chiroptera 010]$ -</PRE> -<HR WIDTH="100%"> -<P> -Notice that each <i>Block ctor</i> has a corresponding <i>Block dtor</i>. -We've proven the point that all memory gets cleaned up. We also see that -both threads get to do some work and that both close as expected. -<P> -It's also worth mentioning that it's just an accident that all of the blocks -are created and enqueued before any are processed. Run the test on a multi-processor -or with more iterations and you'll see some get processed before all are created. -SHAR_EOF - $shar_touch -am 0124153299 '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' -d2a471df09308f89a611a7aa0218737f page06.pre -SHAR_EOF - else - shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page06.pre'`" - test 1493 -eq "$shar_count" || - $echo 'page06.pre:' 'original size' '1493,' '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' && -X -That's it for Tutorial 10. There are some esoteric changes between the thread-pool server -and this application but it's basically the same. In the next tutorial I'll modify this just -a bit to move non-trivial data through the queue. -<P> -X -<UL> -<LI><A HREF="Makefile">Makefile</A> -<LI><A HREF="block.h">block.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> -SHAR_EOF - $shar_touch -am 0124153299 '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' -07ae8f9b2a400e46ab102ab8c40a8b81 page07.pre -SHAR_EOF - else - shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page07.pre'`" - test 444 -eq "$shar_count" || - $echo 'page07.pre:' 'original size' '444,' '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> -This looks a lot like our thread-pool server and it even does some things -better. In particular, I've scoped the Task object so that it's destructor -will have a chance to get called before the application exits. -Notice how we write actual data into the message block though. In the thread-pool -server we just provided a pointer. Writting the data is actually a more correct -way of doing things since you don't get into strange pointer casting situations. -What if you want to put complex objects into the message block though? We'll do -that in the next tutorial, let's stick with the basics first. -<P> -On the next page we'll take a look at our Block object... -<P> -SHAR_EOF - $shar_touch -am 0124153399 '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' -10957f28adbff16015bd94bdc01cd779 page02.pst -SHAR_EOF - else - shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page02.pst'`" - test 689 -eq "$shar_count" || - $echo 'page02.pst:' 'original size' '689,' '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> -Ok, nothing really magic there. Some folks just feel a little uncomfortable -not doing an explicit <i>delete</i> on objects they've <i>new</i>'d so I -wanted to show you that the memory really does get cleaned up. -X -SHAR_EOF - $shar_touch -am 0124153399 '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' -f0ce99c3625ad734730e7ac93efd2c8d page03.pst -SHAR_EOF - else - shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page03.pst'`" - test 237 -eq "$shar_count" || - $echo 'page03.pst:' 'original size' '237,' '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> -The only thing here that we didn't see in the thread-pool server is the -ACE_Barrier. The application logic really doesn't need it but it is a -handy way to synchronize the threads at the beginning of svc(). In testing -I found that if I didn't sync svc(), the first thread to get activated would -tend to get all of the messages before the other threads came alive. -SHAR_EOF - $shar_touch -am 0124153399 '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' -2212efef5c096791808b00a5212c4376 page04.pst -SHAR_EOF - else - shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page04.pst'`" - test 387 -eq "$shar_count" || - $echo 'page04.pst:' 'original size' '387,' '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%"> -<P> -This is all pretty straight-forward too. One gottcha we avoided was a memory leak -due to our shutdown message. Notice that svc() enqueues that block without bothering -to see if there are any more threads to dequeue it. Thats why our dtor can call getq() -without worrying about blocking infinitely: it knows the message block will be there. -SHAR_EOF - $shar_touch -am 0124153399 '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' -54b2e8e21aa451c7a3a227da8069bdf7 page05.pst -SHAR_EOF - else - shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page05.pst'`" - test 366 -eq "$shar_count" || - $echo 'page05.pst:' 'original size' '366,' 'current size' "$shar_count!" - fi -fi -rm -fr _sh15890 -exit 0 diff --git a/docs/tutorials/010/message_queue.cpp b/docs/tutorials/010/message_queue.cpp deleted file mode 100644 index a0be6d5afa9..00000000000 --- a/docs/tutorials/010/message_queue.cpp +++ /dev/null @@ -1,88 +0,0 @@ -// $Id$ - -/* To illustrate the ACE_Message_Queue, we use a derivative of - ACE_Task<>. We also derive from ACE_Message_Block to show that we - don't have memory leaks. */ -#include "task.h" -#include "block.h" - -int -run_test (int iterations, - int threads) -{ - /* Create and start an instance of our Task object. */ - Task task (threads); - - if (task.open () == -1) - ACE_ERROR_RETURN ((LM_ERROR, - "%p\n", - "open"), - -1); - - /* Give the threads a moment to open. This isn't really necessary - but if we don't we find that all of our blocks are constructed and - enqueued before any of the threads get created. Basically, the - sleep() makes the output look more interesting. */ - ACE_OS::sleep (ACE_Time_Value (1)); - - int i; - for (i = 0; i < iterations; ++i) - { - /* Create a new message block to hold our data. Here, we ask - for a block that has 128 bytes of data space. */ - Block *message; - ACE_NEW_RETURN (message, - Block (128), - -1); - - /* Grab the "write pointer". This is a pointer into the data - area where we can write our data. After writting the data you - have to increment the wr_ptr() so that subsequent writes won't - clobber what you've put there. */ - ACE_OS::sprintf (message->wr_ptr (), - "This is message %d.", - i); - message->wr_ptr (ACE_OS::strlen (message->rd_ptr ())); - - /* Put the message block into the queue. One of the threads in - the Task object will pick up the block and "do work" on it. */ - if (task.putq (message) == -1) - break; - } - - /* Once we're done, we have to signal the Task objects to shut - down. There are several choices including: - Send a message of - zero length - Send a message with a special content I don't like - these choices because they're likely to interfere with application - logic. Instead, I use the message type feature to send a message - of type "hangup". The default type is MB_DATA, so when the tasks - get a MB_HANGUP type, they know to go away. */ - Block *message; - - ACE_NEW_RETURN (message, - Block (), - -1); - message->msg_type (ACE_Message_Block::MB_HANGUP); - task.putq (message); - - /* Wait for the threads in our task object to go away. */ - task.wait (); - - return 0; -} - -int -main (int argc, char *argv[]) -{ - /* Set the number of iterations through our putq() loop and the - number of threads to use in our Task<> derivative. */ - int iterations = argc > 1 ? atoi (argv[1]) : 9; - int threads = argc > 2 ? atoi (argv[2]) : 2; - - run_test (iterations, threads); - - ACE_DEBUG ((LM_DEBUG, - "(%P|%t) Application exiting\n")); - - return 0; -} diff --git a/docs/tutorials/010/page01.html b/docs/tutorials/010/page01.html deleted file mode 100644 index 8e27323bd1a..00000000000 --- a/docs/tutorials/010/page01.html +++ /dev/null @@ -1,60 +0,0 @@ -<HTML> -<HEAD> - <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> - <META NAME="Author" CONTENT="James CE Johnson"> - <TITLE>ACE Tutorial 010</TITLE> -</HEAD> -<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#000FFF" VLINK="#FF0F0F"> - -<CENTER><B><FONT SIZE=+2>ACE Tutorial 010</FONT></B></CENTER> - -<CENTER><B><FONT SIZE=+2>Passing chunks of data through an ACE_Message_Queue</FONT></B></CENTER> - - -<P> -<HR WIDTH="100%"> -<P> -In an earlier tutorial we briefly introduced ACE_Message_Queue. In this -tutorial we'll go into a bit more detail. -<P> -ACE_Message_Queue is modeled after Unix System V IPC mechanisms. The basic -idea is that you put a block of data into one end of the Queue and take it -out of the other end. Your basic FIFO in other words. The SysV mechanism -works great for passing these blocks of data between processes on the same -host but it's a bit overkill for moving blocks between threads. You could -use a pipe, socket or similar mechanism but that still has more overhead than -we really want just for moving data between threads. Process-global memory -is a good technique but then you need a way to signal the "listening" threads. -The ACE_Message_Queue is a better approach: Create blocks of data and enqueue -them in one thread while another thread (or threads) dequeue and perform work. -<P> -Kirthika's Abstract: -<UL> -The Message Queue is a FIFO accessible from multiple threads. -That is, a thread puts the produced blocks of data on the message queue -to be consumed by some other thread/threads and processed. In this -tutorial, we see how effectively the Message Queue in a ACE_Task can be -used to pass data among threads in the thread pool. -(this is very similar to -<A HREF="../007/page01.html">Tutorial 7</A> - wherein we implemented a -thread-pool server).Here, actual data is passed between the threads and -also an ACE_Barrier has been used to provide synchronisation among -multiple threads. -<P> -The Message Queue consists of Message Blocks, each of which has a read -and write pointer. Using these pointers the message blocks can be -accessed for reading and writing operations. The ACE_Task::svc() method -will put the block onto the queue without bothering about the existence -of a consumer for that block. A thread from the thread pool obtains the -block from the queue, and checks to see whether the block_type is -MB_HANGUP. If so, it puts the block back on the queue for its -peers and exits. Otherwise, it reads the block and processes it before -releasing it. -<P> -This simple tutorial makes us aware of the usage and importance of the -Message Queue which could be used to our advantage especially for -multithreaded applications. -</UL> -<P><HR WIDTH="100%"> -<CENTER>[<A HREF="../online-tutorials.html">Tutorial Index</A>] [<A HREF="page02.html">Continue This Tutorial</A>]</CENTER> diff --git a/docs/tutorials/010/page02.html b/docs/tutorials/010/page02.html deleted file mode 100644 index 49beffefbd9..00000000000 --- a/docs/tutorials/010/page02.html +++ /dev/null @@ -1,125 +0,0 @@ -<HTML> -<HEAD> - <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> - <META NAME="Author" CONTENT="James CE Johnson"> - <TITLE>ACE Tutorial 010</TITLE> -</HEAD> -<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#000FFF" VLINK="#FF0F0F"> - -<CENTER><B><FONT SIZE=+2>ACE Tutorial 010</FONT></B></CENTER> - -<CENTER><B><FONT SIZE=+2>Passing chunks of data through an ACE_Message_Queue</FONT></B></CENTER> - - -<P> -<HR WIDTH="100%"> - -We'll look first at <A HREF="message_queue.cpp">main()</A>. -<P> - -<HR WIDTH="100%"> -<PRE> -<font color=red>// $Id$</font> - -<font color=red>/* To illustrate the ACE_Message_Queue, we use a derivative of - ACE_Task<>. We also derive from ACE_Message_Block to show that we - don't have memory leaks. */</font> -<font color=blue>#include</font> "<font color=green>task.h</font>" -<font color=blue>#include</font> "<font color=green>block.h</font>" - -int -run_test (int iterations, - int threads) -{ - <font color=red>/* Create and start an instance of our Task object. */</font> - Task task (threads); - - if (task.open () == -1) - ACE_ERROR_RETURN ((LM_ERROR, - "<font color=green>%p\n</font>", - "<font color=green>open</font>"), - -1); - - <font color=red>/* Give the threads a moment to open. This isn't really necessary - but if we don't we find that all of our blocks are constructed and - enqueued before any of the threads get created. Basically, the - sleep() makes the output look more interesting. */</font> - <font color=#008888>ACE_OS::sleep</font> (ACE_Time_Value (1)); - - int i; - for (i = 0; i < iterations; ++i) - { - <font color=red>/* Create a new message block to hold our data. Here, we ask - for a block that has 128 bytes of data space. */</font> - Block *message; - ACE_NEW_RETURN (message, - Block (128), - -1); - - <font color=red>/* Grab the "<font color=green>write pointer</font>". This is a pointer into the data - area where we can write our data. After writting the data you - have to increment the wr_ptr() so that subsequent writes won't - clobber what you've put there. */</font> - <font color=#008888>ACE_OS::sprintf</font> (message->wr_ptr (), - "<font color=green>This is message %d.</font>", - i); - message->wr_ptr (<font color=#008888>ACE_OS::strlen</font> (message->rd_ptr ())); - - <font color=red>/* Put the message block into the queue. One of the threads in - the Task object will pick up the block and "<font color=green>do work</font>" on it. */</font> - if (task.putq (message) == -1) - break; - } - - <font color=red>/* Once we're done, we have to signal the Task objects to shut - down. There are several choices including: - Send a message of - zero length - Send a message with a special content I don't like - these choices because they're likely to interfere with application - logic. Instead, I use the message type feature to send a message - of type "<font color=green>hangup</font>". The default type is MB_DATA, so when the tasks - get a MB_HANGUP type, they know to go away. */</font> - Block *message; - - ACE_NEW_RETURN (message, - Block (), - -1); - message->msg_type (<font color=#008888>ACE_Message_Block::MB_HANGUP</font>); - task.putq (message); - - <font color=red>/* Wait for the threads in our task object to go away. */</font> - task.wait (); - - return 0; -} - -int -main (int argc, char *argv[]) -{ - <font color=red>/* Set the number of iterations through our putq() loop and the - number of threads to use in our Task<> derivative. */</font> - int iterations = argc > 1 ? atoi (argv[1]) : 9; - int threads = argc > 2 ? atoi (argv[2]) : 2; - - run_test (iterations, threads); - - ACE_DEBUG ((LM_DEBUG, - "<font color=green>(%P|%t) Application exiting\n</font>")); - - return 0; -} -</PRE> -<HR WIDTH="100%"> -<P> -This looks a lot like our thread-pool server and it even does some things -better. In particular, I've scoped the Task object so that it's destructor -will have a chance to get called before the application exits. -Notice how we write actual data into the message block though. In the thread-pool -server we just provided a pointer. Writting the data is actually a more correct -way of doing things since you don't get into strange pointer casting situations. -What if you want to put complex objects into the message block though? We'll do -that in the next tutorial, let's stick with the basics first. -<P> -On the next page we'll take a look at our Block object... -<P> -<P><HR WIDTH="100%"> -<CENTER>[<A HREF="../online-tutorials.html">Tutorial Index</A>] [<A HREF="page03.html">Continue This Tutorial</A>]</CENTER> diff --git a/docs/tutorials/010/page03.html b/docs/tutorials/010/page03.html deleted file mode 100644 index 84d9b3bb6f0..00000000000 --- a/docs/tutorials/010/page03.html +++ /dev/null @@ -1,73 +0,0 @@ -<HTML> -<HEAD> - <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> - <META NAME="Author" CONTENT="James CE Johnson"> - <TITLE>ACE Tutorial 010</TITLE> -</HEAD> -<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#000FFF" VLINK="#FF0F0F"> - -<CENTER><B><FONT SIZE=+2>ACE Tutorial 010</FONT></B></CENTER> - -<CENTER><B><FONT SIZE=+2>Passing chunks of data through an ACE_Message_Queue</FONT></B></CENTER> - - -<P> -<HR WIDTH="100%"> -Our <A HREF="block.h">Block</A> object is a very simple derivative -of the ACE_Message_Block. The only reason I created it was to prove -that the message blocks to, indeed, get freed when we're done with 'em. -<P> - -<HR WIDTH="100%"> -<PRE> -<font color=red>// $Id$</font> - -<font color=blue>#ifndef</font> <font color=purple>BLOCK_H</font> -<font color=blue>#define</font> <font color=purple>BLOCK_H</font> - -<font color=blue>#include</font> "<A HREF="../../../ace/Message_Block.h">ace/Message_Block.h</A>" - -<font color=blue>#if !defined</font> (<font color=purple>ACE_LACKS_PRAGMA_ONCE</font>) -<font color=blue># pragma</font> <font color=purple>once</font> -<font color=blue>#endif</font> <font color=red>/* ACE_LACKS_PRAGMA_ONCE */</font> - -<font color=red>/* This simple ACE_Message_Block derivative will inform us of it's - construction and destruction. We'll use this to assure ourselves - that we don't have any memory leaks. In a real application, of - course, this isn't necessary. */</font> -class Block : public ACE_Message_Block -{ -public: - Block (void) - { - ACE_DEBUG ((LM_DEBUG, - "<font color=green>(%P|%t) Block ctor 0x%x\n</font>", - (void *) this)); - } - - Block (size_t size) - : ACE_Message_Block (size) - { - ACE_DEBUG ((LM_DEBUG, - "<font color=green>(%P|%t) Block ctor 0x%x\n</font>", - (void *) this)); - } - - virtual ~Block (void) - { - ACE_DEBUG ((LM_DEBUG, - "<font color=green>(%P|%t) Block dtor 0x%x\n</font>", - (void *) this)); - } -}; - -<font color=blue>#endif</font> <font color=red>/* BLOCK_H */</font> -</PRE> -<HR WIDTH="100%"> -<P> -Ok, nothing really magic there. Some folks just feel a little uncomfortable -not doing an explicit <i>delete</i> on objects they've <i>new</i>'d so I -wanted to show you that the memory really does get cleaned up. - -<P><HR WIDTH="100%"> -<CENTER>[<A HREF="../online-tutorials.html">Tutorial Index</A>] [<A HREF="page04.html">Continue This Tutorial</A>]</CENTER> diff --git a/docs/tutorials/010/page04.html b/docs/tutorials/010/page04.html deleted file mode 100644 index a36a8d8bd29..00000000000 --- a/docs/tutorials/010/page04.html +++ /dev/null @@ -1,76 +0,0 @@ -<HTML> -<HEAD> - <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> - <META NAME="Author" CONTENT="James CE Johnson"> - <TITLE>ACE Tutorial 010</TITLE> -</HEAD> -<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#000FFF" VLINK="#FF0F0F"> - -<CENTER><B><FONT SIZE=+2>ACE Tutorial 010</FONT></B></CENTER> - -<CENTER><B><FONT SIZE=+2>Passing chunks of data through an ACE_Message_Queue</FONT></B></CENTER> - - -<P> -<HR WIDTH="100%"> -Our <A HREF="task.h">Task</A> object executes in one or more threads -and reads from the message queue it contains. -<P> - -<HR WIDTH="100%"> -<PRE> -<font color=red>// $Id$</font> - -<font color=blue>#ifndef</font> <font color=purple>TASK_H</font> -<font color=blue>#define</font> <font color=purple>TASK_H</font> - -<font color=blue>#include</font> "<A HREF="../../../ace/Task.h">ace/Task.h</A>" - -<font color=blue>#if !defined</font> (<font color=purple>ACE_LACKS_PRAGMA_ONCE</font>) -<font color=blue># pragma</font> <font color=purple>once</font> -<font color=blue>#endif</font> <font color=red>/* ACE_LACKS_PRAGMA_ONCE */</font> - -<font color=red>/* Like the thread-pool server tutorial, we'll derive from ACE_Task<>. - Our goal here is to show off the ACE_Message_Queue and the best way - to do that is to use one to pass data between threads. The easiest - way to create threads is with ACE_Task<> */</font> -class Task : public ACE_Task <ACE_MT_SYNCH> -{ -public: - - typedef ACE_Task <ACE_MT_SYNCH> inherited; - - <font color=red>/* The constructor/destructor are simple but take care of some - necessary housekeeping. */</font> - Task (size_t n_threads); - ~Task (void); - - <font color=red>/* open() will kick off our thread pool for us. */</font> - int open (void * = 0); - - <font color=red>/* Our worker method */</font> - int svc (void); - - <font color=red>/* All we'll do here is print a message to the user. */</font> - int close (u_long flags = 0); - -protected: - <font color=red>/* Just to be clever, I'll use an ACE_Barrier to cause the threads - to sync in svc() before doing any real work. */</font> - ACE_Barrier barrier_; - - size_t n_threads_; - <font color=red>// Number of threads in the pool.</font> -}; - -<font color=blue>#endif</font> <font color=red>/* TASK_H */</font> -</PRE> -<HR WIDTH="100%"> -<P> -The only thing here that we didn't see in the thread-pool server is the -ACE_Barrier. The application logic really doesn't need it but it is a -handy way to synchronize the threads at the beginning of svc(). In testing -I found that if I didn't sync svc(), the first thread to get activated would -tend to get all of the messages before the other threads came alive. -<P><HR WIDTH="100%"> -<CENTER>[<A HREF="../online-tutorials.html">Tutorial Index</A>] [<A HREF="page05.html">Continue This Tutorial</A>]</CENTER> diff --git a/docs/tutorials/010/page05.html b/docs/tutorials/010/page05.html deleted file mode 100644 index dca2a02b74e..00000000000 --- a/docs/tutorials/010/page05.html +++ /dev/null @@ -1,164 +0,0 @@ -<HTML> -<HEAD> - <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> - <META NAME="Author" CONTENT="James CE Johnson"> - <TITLE>ACE Tutorial 010</TITLE> -</HEAD> -<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#000FFF" VLINK="#FF0F0F"> - -<CENTER><B><FONT SIZE=+2>ACE Tutorial 010</FONT></B></CENTER> - -<CENTER><B><FONT SIZE=+2>Passing chunks of data through an ACE_Message_Queue</FONT></B></CENTER> - - -<P> -<HR WIDTH="100%"> - -Our <A HREF="task.cpp">Task</A> object definition. -<P> -Something to look at here is the ACE_Barrier usage. In the -constructor, we tell the barrier how many threads we're using. Then, -in the svc() method, we use the barrier's wait() method. You can -think of the barrier as a semaphore initialized to the thread count. - Each time wait() -is invoked, the semaphore is decremented and the thread is blocked. - When the count equals zero, all threads are unblocked and allowed to -continue. -<P> -<font size=-1>Note: This isn't the way ACE_Barrier really works, it's -just an analogy</font> - -<HR WIDTH="100%"> -<PRE> -<font color=red>// $Id$</font> - -<font color=blue>#include</font> "<font color=green>task.h</font>" -<font color=blue>#include</font> "<font color=green>block.h</font>" - -<font color=red>/* Set our housekeeping pointer to NULL and tell the user we exist. */</font> -<font color=#008888>Task::Task</font> (size_t n_threads) - : barrier_ (n_threads), - n_threads_ (n_threads) -{ - ACE_DEBUG ((LM_DEBUG, - "<font color=green>(%P|%t) Task ctor 0x%x\n</font>", - (void *) this)); -} - -<font color=red>/* Take care of cleanup & tell the user we're going away. */</font> -<font color=#008888>Task::~Task</font> (void) -{ - ACE_DEBUG ((LM_DEBUG, - "<font color=green>(%P|%t) Task dtor 0x%x\n</font>", - (void *) this)); - - <font color=red>/* Get our shutdown notification out of the queue and release it. */</font> - ACE_Message_Block *message; - - <font color=red>/* Like the getq() in svc() below, this will block until a message - arrives. By blocking, we know that the destruction will be paused - until the last thread is done with the message block. */</font> - this->getq (message); - message->release (); -} - -<font color=red>/* Open the object to do work. Next, we activate the Task into the - number of requested threads. */</font> -int -<font color=#008888>Task::open</font> (void *unused) -{ - ACE_UNUSED_ARG (unused); - - return this->activate (THR_NEW_LWP, - n_threads_); -} - -<font color=red>/* Tell the user we're closing and invoke the baseclass' close() to - take care of things. */</font> -int -<font color=#008888>Task::close</font> (u_long flags) -{ - ACE_DEBUG ((LM_DEBUG, - "<font color=green>(%P|%t) Task close 0x%x\n</font>", - (void *) this)); - return <font color=#008888>inherited::close</font> (flags); -} - -<font color=red>/* Our svc() method waits for work on the queue and then processes - that work. */</font> -int -<font color=#008888>Task::svc</font> (void) -{ - <font color=red>/* This will cause all of the threads to wait on this line until all - have invoked this method. The net result is that no thread in the - Task will get a shot at the queue until all of the threads are - active. There's no real need to do this but it's an easy intro - into the use of ACE_Barrier. */</font> - this->barrier_.wait (); - - ACE_DEBUG ((LM_DEBUG, - "<font color=green>(%P|%t) Task 0x%x starts in thread %d\n</font>", - (void *) this, - <font color=#008888>ACE_Thread::self</font> ())); - - <font color=red>/* Remember that get() needs a reference to a pointer. To save - stack thrashing we'll go ahead and create a pointer outside of the - almost- infinite loop. */</font> - ACE_Message_Block *message; - - for (;;) - { - <font color=red>/* Get a message from the queue. Note that getq() will block - until a message shows up. That makes us very - processor-friendly. */</font> - if (this->getq (message) == -1) - ACE_ERROR_RETURN ((LM_ERROR, - "<font color=green>%p\n</font>", - "<font color=green>getq</font>"), - -1); - <font color=red>/* If we got the shutdown request, we need to go away. */</font> - if (message->msg_type () == <font color=#008888>ACE_Message_Block::MB_HANGUP</font>) - { - <font color=red>/* Forward the request to any peer threads. */</font> - this->putq (message); - - <font color=red>/* Leave the infinite loop so that the thread exits. */</font> - break; - } - - <font color=red>/* The message queue stores char* data. We use rd_ptr() to get - to the beginning of the data. */</font> - const char *cp = message->rd_ptr (); - - <font color=red>/* Move the rd_ptr() past the data we read. This isn't real - useful here since we won't be reading any more from the block - but it's a good habit to get into. */</font> - message->rd_ptr (<font color=#008888>ACE_OS::strlen</font> (cp)); - - <font color=red>/* Display the block's address and data to the user. */</font> - ACE_DEBUG ((LM_DEBUG, - "<font color=green>(%P|%t) Block 0x%x contains (%s)\n</font>", - (void *) message, - cp)); - - <font color=red>/* Pretend that it takes a while to process the data. */</font> - <font color=#008888>ACE_OS::sleep</font> (ACE_Time_Value (0, 5000)); - - <font color=red>/* Release the message block. Notice that we never delete a - message block. Blocks are reference counted & the release() - method will take care of the delete when there are no more - references to the data. */</font> - message->release (); - } - - return 0; -} -</PRE> -<HR WIDTH="100%"> -<P> -This is all pretty straight-forward too. One gottcha we avoided was a memory leak -due to our shutdown message. Notice that svc() enqueues that block without bothering -to see if there are any more threads to dequeue it. Thats why our dtor can call getq() -without worrying about blocking infinitely: it knows the message block will be there. -<P><HR WIDTH="100%"> -<CENTER>[<A HREF="../online-tutorials.html">Tutorial Index</A>] [<A HREF="page06.html">Continue This Tutorial</A>]</CENTER> diff --git a/docs/tutorials/010/page06.html b/docs/tutorials/010/page06.html deleted file mode 100644 index 9e50e08c41f..00000000000 --- a/docs/tutorials/010/page06.html +++ /dev/null @@ -1,56 +0,0 @@ -<HTML> -<HEAD> - <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> - <META NAME="Author" CONTENT="James CE Johnson"> - <TITLE>ACE Tutorial 010</TITLE> -</HEAD> -<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#000FFF" VLINK="#FF0F0F"> - -<CENTER><B><FONT SIZE=+2>ACE Tutorial 010</FONT></B></CENTER> - -<CENTER><B><FONT SIZE=+2>Passing chunks of data through an ACE_Message_Queue</FONT></B></CENTER> - - -<P> -<HR WIDTH="100%"> - -Since I added Block just to give us output, let's take a look at that output. - -<P> -<HR WIDTH="100%"> -<PRE> -[jcej@chiroptera 010]$./message_queue 4 2 -(8910|1024) Task ctor 0xbffff9c4 -(8910|2050) Task 0xbffff9c4 starts in thread 2050 -(8910|1025) Task 0xbffff9c4 starts in thread 1025 -(8910|1024) Block ctor 0x8052398 -(8910|1024) Block ctor 0x8052488 -(8910|1024) Block ctor 0x8052578 -(8910|1024) Block ctor 0x8052668 -(8910|1024) Block ctor 0x8052758 -(8910|1025) Block 0x8052398 contains (This is message 0.) -(8910|2050) Block 0x8052488 contains (This is message 1.) -(8910|1025) Block dtor 0x8052398 -(8910|1025) Block 0x8052578 contains (This is message 2.) -(8910|2050) Block dtor 0x8052488 -(8910|2050) Block 0x8052668 contains (This is message 3.) -(8910|1025) Block dtor 0x8052578 -(8910|1025) Task close 0xbffff9c4 -(8910|2050) Block dtor 0x8052668 -(8910|2050) Task close 0xbffff9c4 -(8910|1024) Task dtor 0xbffff9c4 -(8910|1024) Block dtor 0x8052758 -(8910|1024) Application exiting -[jcej@chiroptera 010]$ -</PRE> -<HR WIDTH="100%"> -<P> -Notice that each <i>Block ctor</i> has a corresponding <i>Block dtor</i>. -We've proven the point that all memory gets cleaned up. We also see that -both threads get to do some work and that both close as expected. -<P> -It's also worth mentioning that it's just an accident that all of the blocks -are created and enqueued before any are processed. Run the test on a multi-processor -or with more iterations and you'll see some get processed before all are created. -<P><HR WIDTH="100%"> -<CENTER>[<A HREF="../online-tutorials.html">Tutorial Index</A>] [<A HREF="page07.html">Continue This Tutorial</A>]</CENTER> diff --git a/docs/tutorials/010/page07.html b/docs/tutorials/010/page07.html deleted file mode 100644 index 130fa539f60..00000000000 --- a/docs/tutorials/010/page07.html +++ /dev/null @@ -1,30 +0,0 @@ -<HTML> -<HEAD> - <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> - <META NAME="Author" CONTENT="James CE Johnson"> - <TITLE>ACE Tutorial 010</TITLE> -</HEAD> -<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#000FFF" VLINK="#FF0F0F"> - -<CENTER><B><FONT SIZE=+2>ACE Tutorial 010</FONT></B></CENTER> - -<CENTER><B><FONT SIZE=+2>Passing chunks of data through an ACE_Message_Queue</FONT></B></CENTER> - - -<P> -<HR WIDTH="100%"> - -That's it for Tutorial 10. There are some esoteric changes between the thread-pool server -and this application but it's basically the same. In the next tutorial I'll modify this just -a bit to move non-trivial data through the queue. -<P> - -<UL> -<LI><A HREF="Makefile">Makefile</A> -<LI><A HREF="block.h">block.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> -<P><HR WIDTH="100%"> -<CENTER>[<A HREF="../online-tutorials.html">Tutorial Index</A>] </CENTER> diff --git a/docs/tutorials/010/task.cpp b/docs/tutorials/010/task.cpp deleted file mode 100644 index 8fa62ee0e7c..00000000000 --- a/docs/tutorials/010/task.cpp +++ /dev/null @@ -1,123 +0,0 @@ -// $Id$ - -#include "task.h" -#include "block.h" - -/* Set our housekeeping pointer to NULL and tell the user we exist. */ -Task::Task (size_t n_threads) - : barrier_ (n_threads), - n_threads_ (n_threads) -{ - ACE_DEBUG ((LM_DEBUG, - "(%P|%t) Task ctor 0x%x\n", - (void *) this)); -} - -/* Take care of cleanup & tell the user we're going away. */ -Task::~Task (void) -{ - ACE_DEBUG ((LM_DEBUG, - "(%P|%t) Task dtor 0x%x\n", - (void *) this)); - - /* Get our shutdown notification out of the queue and release it. */ - ACE_Message_Block *message; - - /* Like the getq() in svc() below, this will block until a message - arrives. By blocking, we know that the destruction will be paused - until the last thread is done with the message block. */ - this->getq (message); - message->release (); -} - -/* Open the object to do work. Next, we activate the Task into the - number of requested threads. */ -int -Task::open (void *unused) -{ - ACE_UNUSED_ARG (unused); - - return this->activate (THR_NEW_LWP, - n_threads_); -} - -/* Tell the user we're closing and invoke the baseclass' close() to - take care of things. */ -int -Task::close (u_long flags) -{ - ACE_DEBUG ((LM_DEBUG, - "(%P|%t) Task close 0x%x\n", - (void *) this)); - return inherited::close (flags); -} - -/* Our svc() method waits for work on the queue and then processes - that work. */ -int -Task::svc (void) -{ - /* This will cause all of the threads to wait on this line until all - have invoked this method. The net result is that no thread in the - Task will get a shot at the queue until all of the threads are - active. There's no real need to do this but it's an easy intro - into the use of ACE_Barrier. */ - this->barrier_.wait (); - - ACE_DEBUG ((LM_DEBUG, - "(%P|%t) Task 0x%x starts in thread %d\n", - (void *) this, - ACE_Thread::self ())); - - /* Remember that get() needs a reference to a pointer. To save - stack thrashing we'll go ahead and create a pointer outside of the - almost- infinite loop. */ - ACE_Message_Block *message; - - for (;;) - { - /* Get a message from the queue. Note that getq() will block - until a message shows up. That makes us very - processor-friendly. */ - if (this->getq (message) == -1) - ACE_ERROR_RETURN ((LM_ERROR, - "%p\n", - "getq"), - -1); - /* If we got the shutdown request, we need to go away. */ - if (message->msg_type () == ACE_Message_Block::MB_HANGUP) - { - /* Forward the request to any peer threads. */ - this->putq (message); - - /* Leave the infinite loop so that the thread exits. */ - break; - } - - /* The message queue stores char* data. We use rd_ptr() to get - to the beginning of the data. */ - const char *cp = message->rd_ptr (); - - /* Move the rd_ptr() past the data we read. This isn't real - useful here since we won't be reading any more from the block - but it's a good habit to get into. */ - message->rd_ptr (ACE_OS::strlen (cp)); - - /* Display the block's address and data to the user. */ - ACE_DEBUG ((LM_DEBUG, - "(%P|%t) Block 0x%x contains (%s)\n", - (void *) message, - cp)); - - /* Pretend that it takes a while to process the data. */ - ACE_OS::sleep (ACE_Time_Value (0, 5000)); - - /* Release the message block. Notice that we never delete a - message block. Blocks are reference counted & the release() - method will take care of the delete when there are no more - references to the data. */ - message->release (); - } - - return 0; -} diff --git a/docs/tutorials/010/task.h b/docs/tutorials/010/task.h deleted file mode 100644 index 4e0b974a60d..00000000000 --- a/docs/tutorials/010/task.h +++ /dev/null @@ -1,45 +0,0 @@ -// $Id$ - -#ifndef TASK_H -#define TASK_H - -#include "ace/Task.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -/* Like the thread-pool server tutorial, we'll derive from ACE_Task<>. - Our goal here is to show off the ACE_Message_Queue and the best way - to do that is to use one to pass data between threads. The easiest - way to create threads is with ACE_Task<> */ -class Task : public ACE_Task <ACE_MT_SYNCH> -{ -public: - - typedef ACE_Task <ACE_MT_SYNCH> inherited; - - /* The constructor/destructor are simple but take care of some - necessary housekeeping. */ - Task (size_t n_threads); - ~Task (void); - - /* open() will kick off our thread pool for us. */ - int open (void * = 0); - - /* Our worker method */ - int svc (void); - - /* All we'll do here is print a message to the user. */ - int close (u_long flags = 0); - -protected: - /* Just to be clever, I'll use an ACE_Barrier to cause the threads - to sync in svc() before doing any real work. */ - ACE_Barrier barrier_; - - size_t n_threads_; - // Number of threads in the pool. -}; - -#endif /* TASK_H */ |