Document number:       N2760 = 08-0270
Date:                            2008-09-16
Project:                        Programming Language C++, Library Working Group
Reply-to:                      Beman Dawes <bdawes at acm.org>

Input/Output Library Thread Safety

The Library Working Group has identified a need to specify thread safety requirements for Chapter 27, Input/Output Library, components.

This proposal is the result of discussion at the San Francisco meeting of the needs and expectations of users and implementers. It is believed to represent a great deal of existing practice over a long period of time.

Proposed wording

To 27.1 Iostreams requirements [iostreams.requirements], add a new subsection:

27.1.3 Thread safety [iostreams.thread-safety]

Concurrent access to a stream object [string.streams, file.streams], stream buffer object [stream.buffers], or C Library stream [c.files] by multiple threads may result in a data race [intro.multithread] unless otherwise specified [iostream.objects]. [Note: Data races result in undefined behavior [intro.multithread]. --end note]

To 27.3 Standard iostream objects [iostream.objects], add a new paragraph at the end of the section:

Concurrent access to a synchronized [ios.members.static] standard iostream object's formatted and unformatted input [istream] and output [ostream] functions or a standard C stream by multiple threads shall not result in a data race [intro.multithread]. [Note: Users must still synchronize concurrent use of these objects and streams by multiple threads if they wish to avoid interleaved characters. -- end note]