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

ISO C++ Strategic Plan for Multithreading

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

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

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.

Memory Synchronization

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.

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

A Memory Model for C++: Strawman Proposal, Hans-J. Boehm, Hewlett-Packard, April 2005.

Memory Model for Multithreaded C++, Hans-J. Boehm, Hewlett-Packard, Presented at the ISO C++ Spring Conference, Lillehammer, April 2005.

Memory model for multithreaded C++: Issues, Andrei Alexandrescu, Hans Boehm, Kevlin Henney, Ben Hutchings, Douy Lea, Bill Pugh, C++ Standard Committee, WG21/N1777=J16/05-0037

Memory Model for Multithreaded C++, Andrei Alexandrescu, Hans Boehm, Kevlin Henney, Doug Lea, Bill Pugh, Maged Michael, C++ Standard Committee, WG21/NN1738=04-0178

Memory Model for multithreaded C++, Andrei Alexandrescu, Hans Boehm, Kevlin Henney, Doug Lea, Bill Pugh, C++ Standard Committee, WG21/N1680=J16/04-0120

OpenMP Application Program Interface, Version 2.5 Public Draft, November 2004, OpenMP Architecture Review Board, section 1.4 Memory Model (pg 10), section A.13 Illustration of OpenMP memory model (pg 133).

XBD A.4.10 Memory Synchronization.

XBD DRs and proposed replacements.

Defect in XBD 4.10 Memory Synchronization.

Atomic Operations

The standard must define some mechanism for locking.

XBD 4.10 Memory Synchronization.

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

Object Initialization

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?

Thread-Local Storage

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

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.

Issues to be addressed include:

Sun Studio 10: C++ User's Guide, 4.2 Thread-Local Storage, Sun Microsystems.

Thread Management

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.

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.

Programming with POSIX Threads, David R. Butenhof, Addison-Wesley 1997, ISBN 0-201-63392-2.

A Multi-threading Library for Standard C++, Pete Becker, C++ Standard Committee, WG21/N1682=J16/04-0122

POSIX Threads Programming.

OpenMP Application Program Interface Version 2.5 Public Draft, OpenMP.org, November 2004.

Threads Cannot Be Implemented As A Library, Hans-J. Boehm, Hewlett-Packard, 12 November 2004.

uC++ Annotated Reference Manual, Version 5.0, P. A. Buhr, Technical report, Department of Computer Science, University of Waterloo, Waterloo, Ontario, Canada, N2L 3G1, January 2004. See references at the project page.

Boost.Threads, William E. Kempf.

Dinkumware Threads Library, Dinkumware, 2003.

ZThreads, Eric Crahen. [This web page is broken.]

The Adaptive Communication Environment (ACE), Douglas C. Schmidt, Vanderbilt University.

More C++ Threading: From Procedural to Generic, by Example, Kevlin Henney, Curbralan, Presented at the ACCU Spring Conference, Oxford, 16 April 2004.

Asynchronous Programming with Futures, Future Threads, and Traps, Dong Nguyen, Recursion Software.

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

Exceptions

How do exceptions propogate in a multi-threaded environment?

From Beman Dawes:

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.

Timeline

whatwhen
publish strategic planpost-Lillehammer mailing
gather issues, criteria and referencesLillehammer-Quebec mid-term mailing
evaluate referenced models?
choose models?
draft proposalspre-Quebec mailing