<HTML><HEAD><TITLE>N1682=04-0122, A Mult-threading Library for Standard C++ </TITLE></HEAD><BODY>

<CENTER>
<H1><A NAME="A Multi-threading Library for Standard C++">A Multi-threading Library for Standard C++</A></H1>
</CENTER>

<TABLE ALIGN="RIGHT" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD ALIGN="RIGHT"><B><I>Document number:</I></B></TD>
<TD>&nbsp; N1682=04-0122</TD>
</TR>
<TR>
<TD ALIGN="RIGHT"><B><I>Date:</I></B></TD>
<TD>&nbsp; September 10, 2004</TD>
</TR>
<TR>
<TD ALIGN="RIGHT"><B><I>Project:</I></B></TD>
<TD>&nbsp; Programming Language C++</TD>
</TR>
<TR>
<TD ALIGN="RIGHT"><B><I>Reference:</I></B></TD>
<TD>&nbsp; ISO/IEC IS 14882:2003(E)</TD>
</TR>
<TR>
<TD ALIGN="RIGHT"><B><I>Reply to:</I></B></TD>
<TD>&nbsp; Pete Becker</TD>
</TR>
<TR>
<TD></TD>
<TD>&nbsp; Dinkumware, Ltd.</TD>
</TR>
<TR>
<TD></TD>
<TD>&nbsp; petebecker@acm.org</TD>
</TR>
</TABLE>
<BR CLEAR="ALL">

<HR>

<P><B><CODE><A HREF="#Introduction">Introduction</A>
&#183; <A HREF="#Design Overview">Design Overview</A>
&#183; <A HREF="#Implementation Experience">Implementation Experience</A>
</CODE></B></P>

<HR>

<H2><A NAME="Introduction">Introduction</A></H2>

<P>One of the most common complaints about the C and C++ standards is that they
do not provide support for writing portable multi-threaded applications. While
most programmers should not be writing multi-threaded code, with proper high-level
design a set of low-level library primitives can greatly enhance the portability
of multi-threaded code. This paper proposes the addition of such a library to
the C++ standard, either in the upcoming Library Technical Report or in the next
revision of the C++ standard.</P>

<H2><A NAME="Design Overview">Design Overview</A></H2>

<P>The interface to the multi-threading library is described at
<A HREF="http://www.dinkumware.com/manuals/reader.aspx?b=cx/&h=index_thr.html">
the Dinkumware web site</A>. If that link doesn't take you directly to the
documentation, click on the icon with the footprints. The documentation describes
both a C++ interface and a C interface to the multi-threading library. We propose
only the C++ interface. If the committee decides to proceed along these lines we
will make our documentation available for standardization purposes.</P>

<P>The library provides half a dozen library primitives to support multi-threaded
programming. Most of these primitives should be familiar to anyone with experience in
POSIX or Java. The primitives are: threads, thread groups, once functions,
condition variables, mutexes, and thread-specific storage.</P>

<H3><A NAME="Threads">Threads</A></H3>

<P>The class <CODE>thread</CODE> can be used to create a new thread, join an
existing thread, and suspend execution of a thread for a period of time.</P>

<H3><A NAME="Thread Groups">Thread Groups</A></H3>

<P>An object of type <CODE>thread_group</CODE> can be used to manage multiple
threads. It can create a new thread that belongs to the group, it can add threads
to and remove threads from the group, and it can be used to wait until all the
threads in the group have terminated.</P>

<H3><A NAME="Once Functions">Once Functions</A></H3>

<P>The function <CODE>call_once</CODE>, along with its supporting type
<CODE>once_flag</CODE>, can be used to insure that an initialization function
is called only once, even if multiple threads require the same initialization.</P>

<H3><A NAME="Condition Variables">Condition Variables</A></H3>

<P>An object of type <CODE>condition</CODE> can be used to block execution of
threads until another thread indicates that they can proceed. This typically
means that the controlling thread has generated data that is needed by the
blocked threads.</P>

<H3><A NAME="Mutexes">Mutexes</A></H3>

<P>Objects of the various mutex types can be used to insure serial execution
of critical sections of code used by multiple threads.</P>

<H3><A NAME="Thread-specific Storage">Thread-specific Storage</A></H3>

<P>An object of type <CODE>thread_specific_ptr</CODE> can hold a different
pointer value for each thread that accesses it.</P>

<H2><A NAME="Implementation Experience">Implementation Experience</A></H2>

<P>The Dinkumware implementation of this thread library has been in use by
customers for two years without significant problems. The interface is based
on the 
<A HREF="http://www.boost.org/libs/thread/doc/index.html">boost.threads</A>
library, which has also been in wide use for several years.</P>

<P>The underlying C code is based on code in the Dinkum C Library. This code is
widely used on many platforms. It is highly portable and robust.</P>

</BODY></HTML>
