    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: Standard C++</title>
        <link>https://members.accu.org/index.php/articles/508</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>




<div class="xar-mod-head"><span class="xar-mod-title">Programming Topics + Overload Journal #35 - Jan 2000</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c13/">Topics</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c65/">Programming</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c78/">Overload</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c169/">35</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/c65-169/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/articles/c65+169/">All of these categories</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
If those templates do not exist when you try to preview or display a new article,
you'll get this warning :-)  Please place your own templates in themes/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;Standard C++</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 26 January 2000 16:50:56 +00:00 or Wed, 26 January 2000 16:50:56 +00:00</p>
<p><strong>Summary:</strong>&nbsp;</p>
<p><strong>Body:</strong>&nbsp;<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e18" id="d0e18"></a>Why
Threads?</h2>
</div>
<p>Shortly after the C++ standard was announced I read an article
explaining what the standardisation committee will do next. There
is still work to do, it said. Although the standard is not allowed
to change for 7 years some parts will need to be clarified and
ambiguities and inconsistencies will need to be resolved. At some
stage the committee will also have to consider the next C++
standard. The article urged its readers to report parts of the
existing standard that could be improved and to submit suggestions
for its next incarnation.</p>
<p>I thought about this for a while. It seems to me that the
biggest problem with C++ is its sheer size and complexity.
Commercial organisations need to spend a lot of time and money
training C++ programmers. Many of them feel it isn't worth the
investment. What's wrong with C, Java or Visual Basic? Or simply
C++ as a &quot;better C&quot;? To put it another way, C++ is an excellent
language for writing efficient, high-quality, low-level software.
But most software isn't like that. So, if C++ is to remain a
main-stream language, it needs to become smaller, simpler and
easier to use - without losing any of its power and
flexibility.</p>
<p>Unfortunately, but I had no idea how this could be done. So I
thought some more and decided that the standard could be improved
by making it bigger. Like C before it, C++ assumes an underlying
(abstract) machine. It is a single-processor, single-process,
single-thread machine. And most modern software is written to run
in an environment of networked machines running multi-threading,
multi-processing operating systems. If standard C++ doesn't provide
support for such environments C++ programs will always be
platform-specific and the benefits of having a standard will
inevitably be eroded.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e27" id="d0e27"></a>A Hierarchy of
Architectures</h2>
</div>
<p>So, I asked myself, &quot;What other facilities do we need in C++ to
support modern object-oriented, distributed-processing software
environments?&quot;. The answer I gave myself was this:</p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p>threads and thread synchronisation mechanisms;</p>
</li>
<li>
<p>processes, inter-process communications and process
synchronisation mechanisms;</p>
</li>
<li>
<p>networking and support for distributed objects.</p>
</li>
</ul>
</div>
<p>I thought of this as a hierarchy of architectures, each layer
adding facilities to those of the layer beneath. For completeness,
I included support for objects in the hierarchy and produced this
table.</p>
<div class="informaltable">
<table border="1" cellspacing="0">
&lt;colgroup&gt;
&lt;col&gt;
&lt;col&gt;
&lt;col&gt;
&lt;col&gt;
&lt;col&gt;&lt;/colgroup&gt;
&lt;tbody&gt;
<tr>
<td>Architecture</td>
<td>Objects</td>
<td>Threads</td>
<td>Virtual Address Spaces (processors)</td>
<td>Physical Address Spaces (processors)</td>
</tr>
<tr>
<td>procedural</td>
<td>0</td>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>object oriented</td>
<td>n</td>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>multi-threaded</td>
<td>n</td>
<td>n</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>multi-processing</td>
<td>n</td>
<td>n</td>
<td>n</td>
<td>1</td>
</tr>
<tr>
<td>distributed</td>
<td>n</td>
<td>n</td>
<td>n</td>
<td>n</td>
</tr>
&lt;/tbody&gt;
</table>
</div>
<p>Traditional languages, like C, address the procedural level.
Object-oriented languages, like C++ and Java, address the
object-oriented level.</p>
<p>Multi-threading, multi-processing and distributed architectures
are not directly supported by general purpose programming
languages<sup>[<a name="d0e117" href="#ftn.d0e117" id=
"d0e117">1</a>]</sup>. That is provided by operating systems and
libraries. Perhaps it is time to think about adding these
facilities to the C++ Standard Library.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e121" id="d0e121"></a>Support for
Threads in the Standard Library</h2>
</div>
<p>Since then I have been prompted to consider multi-threading
support for other reasons, too. Recent articles in Overload
[<a href="#Kelly31">Kelly31</a>], [<a href="#">Kelly32</a>] and the
C/C++ Users Journal [<a href="#Harrington">Harrington</a>] have
described designs that differ from those I've seen before. There
are also unresolved issues in projects at work related to the use
of threads in object-oriented designs.</p>
<p>So, I set myself the task of exploring current ideas and trying
to design thread support facilities suitable for inclusion in the
standard library. I am aware that this topic has been considered by
a number of people more knowledgeable and more able than myself.
And I believe that threads were omitted from the standard library
partly because existing threading models differ too much for a
'standard' solution to be accepted. The aim was not so much to
define an extension to the standard, but more to learn about the
strengths and weaknesses of different approaches while remaining
focused on the essentials.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e137" id="d0e137"></a>Survey of
Existing Multi-Threading Facilities</h2>
</div>
<p>I looked at a number of software packages providing threads.</p>
<p>They are listed in Table 1.</p>
<div class="table"><a name="d0e144" id="d0e144"></a>
<table summary="A Selection of Thread packages" border="1"
cellspacing="0">
&lt;colgroup&gt;
&lt;col&gt;
&lt;col&gt;
&lt;col&gt;&lt;/colgroup&gt;
&lt;tbody&gt;
<tr>
<td>Category</td>
<td>Package</td>
<td>Description</td>
</tr>
<tr>
<td rowspan="2">Operating system kernel API</td>
<td>Win32 Threads</td>
<td>C functions</td>
</tr>
<tr>
<td>Posix Threads</td>
<td>C functions</td>
</tr>
<tr>
<td>Java interface</td>
<td>Java Threads</td>
<td>Java Classes</td>
</tr>
<tr>
<td rowspan="6">General-purpose C++ interface</td>
<td>Rogue Wave Threads</td>
<td>C++ classes</td>
</tr>
<tr>
<td>Objectspace Thread Classes</td>
<td>C++ classes</td>
</tr>
<tr>
<td>ACE Thread classes</td>
<td>C++ classes</td>
</tr>
<tr>
<td>John Harrington's Thread classes</td>
<td>C++ classes</td>
</tr>
<tr>
<td>Allan Kelly's Class Templates</td>
<td>C++ class templates</td>
</tr>
<tr>
<td>Bio-Rad's Thread Classes</td>
<td>C++ classes</td>
</tr>
<tr>
<td rowspan="3">Vendor-specific C++ interface</td>
<td>MFC CThread Class</td>
<td>C++ classes</td>
</tr>
<tr>
<td>OWL TThread Class</td>
<td>C++ classes</td>
</tr>
<tr>
<td>VCL TThread Class</td>
<td>C++/Delphi classes</td>
</tr>
&lt;/tbody&gt;
</table>
<p class="title c2">Table 1. A Selection of Thread packages</p>
</div>
<p>The packages fall into three main categories: operating system
kernel API, general-purpose C++ interface and vendor-specific
interface. In Java the distinction between operating system and
language is blurred, so that has been given a category of its
own.</p>
<p>Most of the packages listed here have been studied only
superficially. The kernel APIs provide the low-level facilities
that might be used to implement C++ classes. They were examined to
see what building blocks are readily available. Each of the
vendor-specific C++ interfaces depends on facilities not directly
related to the provision of multi-threading (e.g. Window objects).
I regarded these extra facilities as inessential and inappropriate
to a standard library. The Java and general-purpose C++ interface
packages have much in common and I concentrated on these. It is
worth noting, however, that the vendor-specific packages, when
stripped of extraneous features, also have much in common with the
Java and general-purpose groups.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e228" id="d0e228"></a>Core
Facilities</h2>
</div>
<p>I will call the features common to most/all of the
general-purpose interfaces (including Java) the core
facilities.</p>
<p>Table 2 lists the core facilities together with the
corresponding Win32 API functions by way of example. These features
define the thread model that will be discussed in this article.</p>
<div class="table"><a name="d0e235" id="d0e235"></a>
<table summary="Summary of Core Facilities" border="1" cellspacing=
"0">
&lt;colgroup&gt;
&lt;col&gt;
&lt;col&gt;&lt;/colgroup&gt;
&lt;tbody&gt;
<tr>
<td>Description</td>
<td>Win32Function</td>
</tr>
<tr>
<td>Create a new thread</td>
<td>CreateThread</td>
</tr>
<tr>
<td>Terminate the thread function.</td>
<td>ExitThread</td>
</tr>
<tr>
<td>Get a thread's exit code.</td>
<td>GetExitCodeThread</td>
</tr>
<tr>
<td>Destroy a thread.</td>
<td>CloseHandle</td>
</tr>
<tr>
<td>Get a thread's priority.</td>
<td>GetThreadPriority</td>
</tr>
<tr>
<td>Change a thread's priority.</td>
<td>SetThreadPriority</td>
</tr>
<tr>
<td>Suspend execution of the thread function until resumed.</td>
<td>SuspendThread</td>
</tr>
<tr>
<td>Resume execution of the thread function.</td>
<td>ResumeThread</td>
</tr>
<tr>
<td>Suspend execution until some condition becomes true.</td>
<td>WaitForMultipleObjects, etc.</td>
</tr>
<tr>
<td>Suspend execution of the thread function for a specific time
period.</td>
<td>Sleep</td>
</tr>
<tr>
<td>Get the handle of the currently executing thread.</td>
<td>GetCurrentThread</td>
</tr>
<tr>
<td>Get the ID of the currently executing thread.</td>
<td>GetCurrentThreadId</td>
</tr>
<tr>
<td>Wait for the thread function to finish.</td>
<td>WaitForSingleObject</td>
</tr>
&lt;/tbody&gt;
</table>
<p class="title c2">Table 2. Summary of Core Facilities</p>
</div>
<p>In considering these facilities it is important to distinguish
between a thread and the function it is executing. A thread is a
resource provided by the system; a thread function is a
user-defined piece of code.</p>
<p>Other facilities provided by existing implementations include
things like: names for threads (useful for diagnostics), access
control (does the user have permission to create a thread, change
its priority, etc.), ordering relations (<tt class=
"methodname">operator&lt;()</tt>, <tt class=
"methodname">operator==()</tt>, etc.) and support for thread
groups. Support for miscellaneous thread facilities and extensions
is not discussed here.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e320" id="d0e320"></a>The First
Design Challenge</h2>
</div>
<p>The purpose of a thread is to execute a user-defined function
asynchronously with respect to other thread functions. And the
first design challenge is to provide a way of running thread
functions with widely varying interfaces in a thread that accepts
only one, simple thread function interface. I call this the
function signature mismatch problem.</p>
<p>Ideally, we would like the thread library implementation to call
an arbitrary, user-defined function, but the C++ language has no
construct that lets us call a function with an unknown parameter
list. So either we restrict the type of function we can call or we
must find an indirect way of calling any given function.</p>
<p>I shall consider three approaches:</p>
<div class="orderedlist">
<ol type="1">
<li>
<p>Thread-Runs-Function,</p>
</li>
<li>
<p>Thread-Is-Polymorphic-Object,</p>
</li>
<li>
<p>Thread-Runs-Polymorphic-Object.</p>
</li>
</ol>
</div>
<p>The first two are wide-spread; the third is the one we use at
Bio-Rad. The code fragments in Thread-Runs-Function through
Thread-Runs-Polymorphic-Object show the characteristic features of
each approach.</p>
<div class="sect2" lang="en">
<div class="titlepage">
<h3><a name="d0e341" id=
"d0e341"></a>Thread-Runs-Function</h3>
</div>
<pre class="programlisting">
class thread {
public:
  typedef int function (void*);
    // create thread and start thread function
  thread (function*, void*);
. . .
};
</pre>
<p>The thread class in the <span class=
"emphasis"><em>Thread-Runs-Function</em></span> approach is a thin
wrapper around the thread functions in the kernel API. It leaves
responsibility for solving the function signature mismatch problem
entirely in the hands of the programmer. The user is expected to
provide a non-member function (or static member function) with the
same signature as the underlying system call. The exact signature
of the thread function varies from platform to platform, but
typically the thread function takes a <tt class="type">void*</tt>
parameter and returns an integer value (<tt class=
"type">signed</tt> or <tt class="type">unsigned</tt>, <tt class=
"type">int</tt> or <tt class="type">long</tt>).</p>
<p>This is acceptable for procedural-style programming, but less
useful for object-oriented designs. Non-member functions are
usually inappropriate in O-O designs and adding static member
functions just to fit the thread class interface complicates the
implementation. And, of course, the use of a <tt class=
"type">void*</tt> parameter introduces the risk of unsafe type
conversions.</p>
</div>
<div class="sect2" lang="en">
<div class="titlepage">
<h3><a name="d0e371" id=
"d0e371"></a>Thread-Is-Polymorphic-Object</h3>
</div>
<pre class="programlisting">
class thread {
public:
  // create thread, destroy thread
  thread();
  virtual ~thread();
  // start thread function
  void start();
. . .
protected:
  // thread function implementation
  virtual int run() = 0;
  . . .
};
</pre>
<p><span class=
"emphasis"><em>Thread-Is-Polymorphic-Object</em></span> fits better
with the object-oriented style. The static member function is
replaced with a virtual member function and the <tt class=
"type">void*</tt> parameter is replaced with the implicit
<tt class="varname">this</tt> pointer.</p>
<p>The library user must still provide an implementation for a
function with a simple, fixed interface - the virtual <tt class=
"methodname">run()</tt> function. However, it is natural to provide
any data required by the <tt class="methodname">run()</tt> function
as data members of the derived class. The absence of a parameter
list does not adversely affect the design and the resulting code is
elegant and type-safe. The extra level of indirection provided by
the virtual function call helps the application developer to solve
the function signature mismatch problem.</p>
<p>The need to sub-class thread adds complexity to the class
hierarchies, but this is a small price to pay for the extra
convenience and type safety. In a sense, this is what
object-oriented programming is all about. However, with this
approach the thread management functions are tightly coupled with
the application logic and this makes it more difficult to change
the application's threading strategy.</p>
</div>
<div class="sect2" lang="en">
<div class="titlepage">
<h3><a name="d0e396" id=
"d0e396"></a>Thread-Runs-Polymorphic-Object</h3>
</div>
<pre class="programlisting">
class thread
{
public:
  struct function;
  // create thread and start thread 
  // function
  thread (function&amp;);
  . . .
};
struct thread::function{
  // destroy thread function
  virtual ~function() {}
  // thread function implementation
  virtual int run() = 0;
};
</pre>
<p>The <span class=
"emphasis"><em>Thread-Runs-Polymorphic-Object</em></span> approach
retains the main characteristics of <span class=
"emphasis"><em>Thread-Is-Polymorphic-Object</em></span>, but also
separates the concepts of thread and thread function into different
classes. The thread class handles thread management, while the
thread function class encapsulates the application logic.</p>
<p>Here we have an example of the Command design pattern [<a href=
"#GoF">GoF</a>]. The thread class performs the role of the Invoker
and the thread function class performs the role of the abstract
Command class. It is the responsibility of the application
programmer to provide a class derived from <tt class=
"classname">thread::function</tt> to perform the <tt class=
"classname">ConcreteCommand</tt> role. As noted in the Gang-of-Four
book, a Command is an object-oriented replacement for a call-back
function.</p>
<p>For the Command pattern to work it has to solve the function
signature mismatch problem. The abstract <tt class=
"classname">Command</tt> must provide a simple, fixed execution
interface for the Invoker to use. At the same time its
implementation must be able to execute an arbitrary action
function. It is the <tt class="classname">ConcreteCommand</tt>
class that translates the abstract operation into a concrete method
call.</p>
<p>The pattern represents a complete solution to the function
signature mismatch problem, but the thread library can only provide
part of it. The application developer must still provide a concrete
class to implement the <tt class="methodname">run()</tt>
function.</p>
<div class="figure"><a name="d0e433" id="d0e433"></a>
<div class="mediaobject c3"><img src=
"/var/uploads/journals/resources/Command%20Design%20Pattern.png" align="middle" alt=
"Command Design Pattern"></div>
<p class="title c2">Figure 1. Command Design Pattern</p>
</div>
</div>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e439" id=
"d0e439"></a>Templates</h2>
</div>
<p>Designs based on templates are also possible, as described by
Allan Kelly in Overloads 31 and 33 ([<a href=
"#Kelly31">Kelly31</a>], [<a href="#Kelly33">Kelly33</a>]).
However, using a class template doesn't solve the function
signature mismatch problem. Even if the thread function type is
supplied as a template parameter, the template functions must still
assume a fixed interface. In Allan Kelly's articles, for example,
the thread function is assumed to be a class with a <tt class=
"methodname">Run()</tt> member function.</p>
<p>Templates may also lead to code bloat. Some of the code in
Allan's thread template is independent of the template parameters
and the compiler will duplicate that code for every instantiation
of the template. This effect can be controlled by techniques such
as factoring out the common behaviour into a non-template base
class, using member templates and partial specialisations, but even
these techniques are not sufficient here because the duplication
occurs within the member functions.</p>
<p>There is a practical problem associated with templates, too.
Some compilers still require template function bodies to be placed
in the header file and this forces platform-dependent details into
the headers. On Win32 systems, for example, it means a <tt class=
"literal">#include &quot;Windows.h&quot;</tt> in the <tt class=
"filename">thread.h</tt> file to provide definitions of the
<tt class="type">HANDLE</tt> type, the <tt class=
"function">CreateThread()</tt> function, etc.. This leads to
<tt class="literal">#if</tt> directives that clutter the headers
and long compilation times. Even worse, in my view, it turns what
was supposed to be a standard (i.e. non-proprietary) header into
one that depends on every platform it supports!</p>
<p>Templates are not all bad, though. Supplying the thread function
type as a template parameter removes the need to inherit from a
base class and override a virtual function. On the other hand,
polymorphism provides its own benefits - late binding allows the
dynamic type of the thread function to be determined at run time
and this flexibility can be important.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e474" id="d0e474"></a>Sample
Code</h2>
</div>
<p>As a concrete example, suppose we want to print a file in the
background using the following function:</p>
<pre class="programlisting">
  void Printer::print (
          std::string file_name);
</pre>
<p>If our thread library uses the <span class=
"emphasis"><em>Thread-Runs-Function</em></span> design we must
first create a thread function. We also need a simple <tt class=
"literal">struct</tt> to pass the printer and file name information
to the thread function via its single <tt class="type">void*</tt>
parameter. The print function must decode this structure before
calling <tt class="methodname">Printer::print()</tt>.</p>
<pre class="programlisting">
// thread function arguments
struct print_args {
  Printer*  printer;
  std::string* file_name;
};

// thread function
int print_function (void* address){
  print_args* args = static_cast&lt;print_args*&gt;(address);
  Printer* printer   = args-&gt;printer;
  std::string* file_name = args-&gt;file_name;
  printer-&gt;print(*file_name);
  return 0;
}
</pre>
<p>The new print function can be run in a separate thread like
this:</p>
<pre class="programlisting">
Epson_Stylus printer;
std::string file_name(&quot;printer_test.txt&quot;);
print_args args ={&amp;printer, &amp;file_name};
thread print_thread(print_function,&amp;args);
</pre>
<p>Using <span class=
"emphasis"><em>Thread-Runs-Polymorphic-Object</em></span> we must
create a concrete thread function class:</p>
<pre class="programlisting">
// concrete thread function class
class print_function : public thread::function {
public:
  print_function(Printer&amp; p,
                   std::string n)
  : printer(p), file_name(n) {}
private:
  virtual int run() {
    printer.print(file_name);
    return 0;
  }
  Printer&amp;    printer;
  std::string file_name;
};
</pre>
<p>Like the <span class="structname">print_args</span> struct in
the <span class="emphasis"><em>Thread-Runs-Function</em></span>
design the print function class holds information about the printer
and the file to be printed. Now, though, the virtual thread
function has access to that data via the implicit this pointer. No
cast is necessary and no statements are required to decode the data
structure.</p>
<p>The new thread class can be used like this:</p>
<pre class="programlisting">
Epson_Stylus printer;
std::string  file_name(&quot;printer_test.txt&quot;);
print_function print_file(printer,file_name);
thread print_thread(print_function);
</pre>
<p>The quantity of code is similar in both designs, but the
object-oriented style leads to better quality.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e522" id="d0e522"></a>Looking
Ahead</h2>
</div>
<p>So far, we have only considered the fundamental mechanism for
invoking a user-defined function in a separate thread. Most of the
core facilities have not been discussed at all and some of them
raise further design issues. There is one problem that is common to
many of the core facilities; it is the age old problem of how to
balance the need for a simple, consistent interface with the desire
to make available the full power of each underlying
implementation.</p>
<p>As an example of what I mean, a VGA interface can be provided
for just about any video card and this is fine for some
applications. But many applications need more advanced graphical
operations. Of course there are plenty of video cards to choose
from, but they differ in capabilities and native interface. How can
we write a portable graphics library that takes advantage of the
particular features of each card? Threads present us with several
examples of this sort of dilemma and I would like to explore these
in the next article.</p>
<p>Then, beyond the basic thread facilities there are issues of
ownership and synchronisation. In each of the thread designs
presented in this article a parent thread function provides some
data to the child. Sometimes responsibility for those data items
remains with the parent, sometimes it is passed on to the child.
Similarly, a responsible parent will clean up after a child thread
dies, but some parents will die themselves, leaving their children
orphaned. I suggest these issues are best addressed by a more
application-oriented threading model and there is scope for another
article here.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e531" id="d0e531"></a>Summary</h2>
</div>
<p>This article has described three common approaches to basic
thread facilities and discussed their suitability for inclusion in
a standard library. The <span class=
"emphasis"><em>Thread-Runs-Polymorphic-Object</em></span> model
fits well with object-oriented designs and separates the thread
support facilities from the application-specific code.</p>
<p>Providing access to platform-specific facilities and the use of
application-oriented thread models were raised as topics for
further discussion.</p>
</div>
<div class="bibliography">
<div class="titlepage">
<h2><a name="d0e541" id="d0e541"></a>References</h2>
</div>
<div class="bibliomixed"><a name="Kelly31" id="Kelly31"></a>
<p class="bibliomixed">[Kelly31] <span class="citetitle"><i class=
"citetitle">Overload</i></span>, No. 31, April 1999, &quot;Using
Templates to Handle Multi-threading&quot; by Allan Kelly.</p>
</div>
<div class="bibliomixed"><a name="Kelly33" id="Kelly33"></a>
<p class="bibliomixed">[Kelly33] <span class="citetitle"><i class=
"citetitle">Overload</i></span>, No. 33, August 1999, &quot;More
Threading with Templates&quot; by Allan Kelly.</p>
</div>
<div class="bibliomixed"><a name="Harrington" id="Harrington"></a>
<p class="bibliomixed">[Harrington] <span class=
"citetitle"><i class="citetitle">C/C++ Users Journal</i></span>,
Vol. 17 No. 8, August 1999, &quot;Win32 Multithreading Made Easy&quot; by
John Harrington.</p>
</div>
<div class="bibliomixed"><a name="GoF" id="GoF"></a>
<p class="bibliomixed">[GoF] <span class="citetitle"><i class=
"citetitle">&quot;Design Patterns - Elements of Reusable Object-Oriented
Software&quot;</i></span>, by Erich Gamma, Richard Helm, Ralph Johnson
and John Vlissides.</p>
</div>
<div class="bibliomixed"><a name="Stroustrup" id="Stroustrup"></a>
<p class="bibliomixed">[Stroustrup] <span class=
"citetitle"><i class="citetitle">The C++ Programming Language, 3rd
Edition</i></span>, by Bjarne Stroustrup.</p>
</div>
</div>
<div class="footnotes"><br>
<hr class="c4" width="100">
<div class="footnote">
<p><sup>[<a name="ftn.d0e117" href="#d0e117" id=
"ftn.d0e117">1</a>]</sup> By &quot;general purpose programming
languages&quot; I mean languages that don't have their own environment.
This includes C and C, but not Smalltalk and Forth. I'm not sure
how to classify Java!</p>
</div>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
