Thread Unsafe Standard Functions

ISO/IEC JTC1 SC22 WG21 N2827 = 09-0017 - 2009-02-07

Lawrence Crowl, crowl@google.com, Lawrence@Crowl.org
P.J. Plauger, pjp@dinkumware.com
Nick Stoughton, USENIX, nick@usenix.org

Introduction

With the introduction of concurrency into the C++ standard, some functions adopted from the C standard need explicit exemption from the general prohibition on data races in 17.6.5.7 [res.on.data.races].

Already Exempted

The following functions are already exempted in 20.9 [date.time].

asctime ctime gmtime localtime

The following functions are already exempted in 21.5 [c.strings].

strerror strtok

The following functions are already exempted in 26.7 [c.math].

rand

Exemption Revoked

The following functions may have previously been thread unsafe, but must be thread safe to enable effective programming.

atexit at_quick_exit exit fclose free quick_exit malloc signal

Wording

18.9 Other runtime support [support.runtime]

After paragraph 4, add a new paragraph.

The function getenv is not required to avoid data races (17.6.5.7).

21.5 Null-terminated sequence utilities [c.strings]

After paragraph 14, add a new paragraph.

The following functions are not required to avoid data races (17.6.5.7) if the mbstate_t* argument is NULL.

mbrlen mbrtowc mbsrtowc mbtowc wcrtomb wcsrtomb wctomb

22.1.1.5 locale static members [locale.statics]

Edit paragraph 2 as follows.

Effects: Causes future calls to the constructor locale() to return a copy of the argument. If the argument has a name, does

std::setlocale(LC_ALL, loc.name().c_str());

otherwise, the effect on the C locale, if any, is implementation-defined. No library function other than locale::global() shall affect the value returned by locale(). [Note: See (22.4 [c.locales]) for data race considerations when setlocale is invoked. —end note]

22.4 C Library Locales [c.locales]

After paragraph 2, add new paragraph.

The function setlocale is not required to avoid data races (17.6.5.7), and in particular may race with the following functions.

exec fprintf fscanf isalnum isalpha isblank iscntrl isdigit isgraph islower isprint ispunct isspace isupper iswalnum iswalpha iswblank iswcntrl iswctype iswdigit iswgraph iswlower iswprint iswpunct iswspace iswupper iswxdigit isxdigit localeconv mblen mbstowcs mbtowc nl_langinfo setlocale strcoll strerror strfmon strsignal strtod strxfrm tolower toupper towlower towupper uselocale wcscoll wcstod wcstombs wcsxfrm wctomb

27.8.2 C Library files [c.files]

Before "See also", add a new paragraph.

The function tmpnam is not required to avoid data races (17.6.5.7) if its argument is NULL.