<html><head>
<title>ISO C++ Strategic Plan for Multithreading</title>
</head>

<body>
<p>Document Number: SC22/WG21/N1815 = 05-0075
<br>Project: Programming Language C++
<br>Date: 2005-05-02
<br>Author: Lawrence Crowl
<br>Email: Lawrence.Crowl@Sun.com

<h1>ISO C++ Strategic Plan for Multithreading</h1>

<p>This paper outlines the constraints, goals, and steps necessary to
introduce support for multi-threading into the C++ language.

<p>A usable multi-threading model must address several related issues:
memory synchronization, atomic operations, object initialization,
thread-local storage, thread management, and exceptions.

<p>The challenge in defining a C++ threading model that
we need to serve the needs of relatively casual thread programmers
and deliver good performance on modern systems.
This challange will be most severe
in the standardization of memory synchronization.

<h1>Memory Synchronization</h1>

<p>There is consensus to leave the semantics of data races undefined.
That said, "race condition", "deadlock",
and perhaps other common threading terminology
will need working definitions
in 1.3 [intro.defs], 17.1 [lib.definitions],
or a new threading library clause.

<p>There is consensus to clarify the semantics of volatile.
We may also need to clarify the semantics of sequence points.

<p><a href="http://www.hpl.hp.com/personal/Hans_Boehm/c++mm/mm.html">
<cite>A Memory Model for C++: Strawman Proposal</cite></a>,
<a href="mailto:hans.boehm@hp.com">Hans-J. Boehm</a>,
<a href="http://www.hp.com">Hewlett-Packard</a>,
April 2005.

<p><a href="http://www.hpl.hp.com/personal/Hans_Boehm/mmissues.pdf">
<cite>Memory Model for Multithreaded C++</cite></a>,
<a href="mailto:hans.boehm@hp.com">Hans-J. Boehm</a>,
<a href="http://www.hp.com">Hewlett-Packard</a>,
Presented at the ISO C++ Spring Conference,
Lillehammer,
April 2005.

<p><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1777.pdf">
<cite>Memory model for multithreaded C++: Issues</cite></a>,
Andrei Alexandrescu, Hans Boehm, Kevlin Henney, Ben Hutchings,
Douy Lea, Bill Pugh,
<a href="http://www.open-std.org/jtc1/sc22/wg21/">C++ Standard Committee</a>,
WG21/N1777=J16/05-0037

<p><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1738.pdf">
<cite>Memory Model for Multithreaded C++</cite></a>,
Andrei Alexandrescu, Hans Boehm, Kevlin Henney, Doug Lea,
Bill Pugh, Maged Michael,
<a href="http://www.open-std.org/jtc1/sc22/wg21/">C++ Standard Committee</a>,
WG21/NN1738=04-0178

<p><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1680.pdf">
<cite>Memory Model for multithreaded C++</cite></a>,
Andrei Alexandrescu, Hans Boehm, Kevlin Henney, Doug Lea, Bill Pugh,
<a href="http://www.open-std.org/jtc1/sc22/wg21/">C++ Standard Committee</a>,
WG21/N1680=J16/04-0120

<p><a href="http://www.openmp.org/drupal/mp-documents/draft_spec25.pdf">
<cite>OpenMP Application Program Interface</cite></a>,
Version 2.5 Public Draft,
November 2004,
<a href="http://www.openmp.org/">OpenMP Architecture Review Board</a>,
section 1.4 Memory Model (pg 10),
section A.13 Illustration of OpenMP memory model (pg 133).

<p><a href="http://www.opengroup.org/onlinepubs/009695399/xrat/xbd_chap04.html#tag_01_04_10">
XBD A.4.10 Memory Synchronization</a>.

<p><a href="http://www.decadentplace.org.uk/pipermail/cpp-threads_decadentplace.org.uk/2005-April/000222.html">
XBD DRs and proposed replacements</a>.

<p><a href="http://www.opengroup.org/austin/mailarchives/ag/msg03986.html">
Defect in XBD 4.10 Memory Synchronization</a>.

<h2>Atomic Operations</h2>

<p>The standard must define some mechanism for locking.

<p><a href="http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap04.html#tag_04_10">
XBD 4.10 Memory Synchronization</a>.

<p>The standard must define some operations
that will serve as the basis for lock-free data structures.

<h2>Object Initialization</h2>

<p>We must clarify the initialization of program-duration variables,
and in particular function-local static variables,
in the presence of threads.
Are initializations of such objects thread-safe?

<h2>Thread-Local Storage</h2>

<p>Some compiler vendors provide thread-local storage
via a <tt>__thread</tt> storage class specifier.
As this feature is somewhat commonly supported,
we should base the standard on it.

<p>Thread-local storage defines lifetime and scope, not accessibility.
That is, one may take the address of a thread-local variable
and pass it to other threads.

<p>Issues to be addressed include:
<ul>
<li>variables have non-constant addresses
<li>support for dynamic initializers
<li>variable destruction on thread termination
<li>memory consumption bounds
</ul>

<p><a href="http://docs.sun.com/source/819-0496/Language_Extensions.html#pgfId-997650">
<cite>Sun Studio 10: C++ User's Guide</cite></a>,
4.2 Thread-Local Storage,
<a href="http://www.sun.com/">Sun Microsystems</a>.

<h2>Thread Management</h2>

<p>There are many different models for thread management,
many designed for different application environments.
Such diversity makes choosing a model difficult.
Rather than attempt to standardize an application-level solution,
the straw proposal is to provide a standard substrate
for implementation of higher-level facilities.

<ul>
<li>Add value to the pthreads facility.
This may be via exploitation of destructors, etc.
<li>Constrain the pthreads facility in a manner suitable to C++ applications.
In particular, we may eliminate cancellation.
<li>Remain interoperable with the base operating system threading facilities.
<li>Preferably defined a model that is implementable on top of pthreads.
<li>Avoid competing with other well-established standards,
in particular OpenMP.
</ul>

<p>
Note that only some versions of Windows support POSIX,
and only partially at that.
We may have to base our work on "common features"
rather than another standard.

<p><cite>Programming with POSIX Threads</cite>,
David R. Butenhof,
Addison-Wesley 1997,
ISBN 0-201-63392-2.

<p><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1682.html">
<cite>A Multi-threading Library for Standard C++</cite></a>,
Pete Becker,
<a href="http://www.open-std.org/jtc1/sc22/wg21/">C++ Standard Committee</a>,
WG21/N1682=J16/04-0122

<p><a href="http://www.llnl.gov/computing/tutorials/workshops/workshop/pthreads/MAIN.html">
<cite>POSIX Threads Programming</cite></a>.

<p><a href="http://www.openmp.org/drupal/mp-documents/draft_spec25.pdf">
<cite>OpenMP Application Program Interface Version 2.5 Public Draft</cite></a>,
<a href="http://www.openmp.org/">OpenMP.org</a>,
November 2004.

<p><a href="http://www.hpl.hp.com/techreports/2004/HPL-2004-209.pdf">
<cite>Threads Cannot Be Implemented As A Library</cite></a>,
<a href="mailto:hans.boehm@hp.com">Hans-J. Boehm</a>,
<a href="http://www.hp.com">Hewlett-Packard</a>,
12 November 2004.

<p><a href="ftp://plg.uwaterloo.ca/pub/uSystem/uC++.ps.gz">
<cite>uC++ Annotated Reference Manual, Version 5.0</cite></a>,
P. A. Buhr,
Technical report,
Department of Computer Science,
University of Waterloo,
Waterloo,
Ontario,
Canada,
N2L 3G1,
January 2004.
See references at the
<a href="http://plg.uwaterloo.ca/~usystem/uC++.html">project page</a>.

<p><a href="http://www.boost.org/doc/html/threads.html">
<cite>Boost.Threads</cite></a>,
William E. Kempf.

<p><a href="http://www.dinkumware.com/manuals/buyReminder.aspx?b=cx/&h=cppthrd_over.html">
<cite>Dinkumware Threads Library</cite></a>,
<a href="http://www.dinkumware.com">Dinkumware</a>,
2003.

<p><a href="http://zthread.sourceforge.net/"><cite>ZThreads</cite></a>,
Eric Crahen.
[This web page is broken.]

<p><a href="http://www.cs.wustl.edu/~schmidt/ACE.html">
<cite>The Adaptive Communication Environment (ACE)</cite></a>,
<a href="mailto:d.schmidt@vanderbilt.edu">Douglas C. Schmidt</a>,
<a href="http://www.vanderbilt.edu/">Vanderbilt University</a>.

<p><a href="http://www.two-sdg.demon.co.uk/curbralan/papers/accu/MoreC++Threading.pdf">
<cite>More C++ Threading: From Procedural to Generic, by Example</cite></a>,
<a href="mailto:kevlin@curbralan.com">Kevlin Henney</a>,
<a href="http://www.curbralan.com">Curbralan</a>,
Presented at the ACCU Spring Conference,
Oxford,
16 April 2004.

<p><a href="http://www.recursionsw.com/CPlus/Async_Futures.pdf">
<cite>Asynchronous Programming
with Futures, Future Threads, and Traps</cite></a>,
Dong Nguyen,
<a href="http://www.recursionsw.com/">Recursion Software</a>.

<p>
<cite>C++ CONNECTIONS: 20 YEARS OF C++ High-Level Concurrency for C++</cite>,
Peter A. Buhr,
University of Waterloo,
Canada,
18 April 2005.

<h2>Exceptions</h2>

<p>
How do exceptions propogate in a multi-threaded environment?

<p>
From Beman Dawes:
<blockquote>
Not propagating exceptions is very upsetting to some people,
because it locks out whole classes of multi-threaded programs.
Boost heard that loud and clear from a lot of users.
If the core language doesn't propagate exceptions,
then the threading library has to manually capture them,
pass (with attendant copying problems)
the exception object to the parent thread,
and then or otherwise report the problem.
Really messy for the library.
</blockquote>

<h2>Timeline</h2>
<table>
<tr><th>what</th><th>when</th></tr>
<tr><td>publish strategic plan</td><td>post-Lillehammer mailing</td></tr>
<tr><td>gather issues, criteria and references</td><td>Lillehammer-Quebec mid-term mailing</td></tr>
<tr><td>evaluate referenced models</td><td>?</td></tr>
<tr><td>choose models</td><td>?</td></tr>
<tr><td>draft proposals</td><td>pre-Quebec mailing</td></tr>
</table>

</body></html>


