<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<title>Thread Unsafe Standard Functions</title>
</head>
<body>
<h1>Thread Unsafe Standard Functions</h1>

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

<p>
Lawrence Crowl, crowl@google.com, Lawrence@Crowl.org<br>
P.J. Plauger, pjp@dinkumware.com<br>
Nick Stoughton, USENIX, nick@usenix.org
</p>


<h2>Introduction</h2>

<p>
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].
</p>


<h3>Already Exempted</h3>

<p>
The following functions
are already exempted in 20.9 [date.time].
</p>
<blockquote>
<p>
<code>
asctime
ctime
gmtime
localtime
</code>
</p>
</blockquote>

<p>
The following functions
are already exempted in 21.5 [c.strings].
</p>
<blockquote>
<p>
<code>
strerror
strtok
</code>
</p>
</blockquote>


<p>
The following functions
are already exempted in 26.7 [c.math].
</p>
<blockquote>
<p>
<code>
rand
</code>
</p>
</blockquote>

<h3>Exemption Revoked</h3>

<p>
The following functions may have previously been thread unsafe,
but must be thread safe to enable effective programming.
</p>
<blockquote>
<p>
<code>
atexit
at_quick_exit
exit
fclose
free
quick_exit
malloc
signal
</code>
</p>
</blockquote>

<h2>Wording</h2>

<h3>18.9 Other runtime support [support.runtime]</h3>

<p>
After paragraph 4, add a new paragraph.
</p>
<blockquote>
<p>
The function <code>getenv</code>
is not required to avoid data races (17.6.5.7).
</p>
</blockquote>

<h3>21.5 Null-terminated sequence utilities [c.strings]</h3>

<p>
After paragraph 14, add a new paragraph.
</p>
<blockquote>
<p>
The following functions
are not required to avoid data races (17.6.5.7)
if the <code>mbstate_t*</code> argument is <code>NULL</code>.
</p>
<blockquote>
<p>
<code>
mbrlen
mbrtowc
mbsrtowc
mbtowc
wcrtomb
wcsrtomb
wctomb
</code>
</p>
</blockquote>
</blockquote>

<h3>22.1.1.5 locale static members [locale.statics]</h3>

<p>
Edit paragraph 2 as follows.
</p>
<blockquote>
<p>
<i>Effects:</i>
Causes future calls to the constructor <code>locale()</code>
to return a copy of the argument.
If the argument has a name,
does
</p>
<blockquote>
<p>
<code>
std::setlocale(LC_ALL, loc.name().c_str());
</code>
</p>
</blockquote>
<p>
otherwise, the effect on the C locale, if any, is implementation-defined.
No library function other than <code>locale::global()</code>
shall affect the value returned by <code>locale()</code>.
<ins>
[<i>Note:</i>
See (22.4 [c.locales]) for data race considerations
when <code>setlocale</code> is invoked.
&mdash;<i>end note</i>]
</ins>
</p>
</blockquote>

<h3>22.4 C Library Locales [c.locales]</h3>

<p>
After paragraph 2, add new paragraph.
</p>
<blockquote>
<p>
The function <code>setlocale</code>
is not required to avoid data races (17.6.5.7),
and in particular may race with the following functions.
</p>
<blockquote>
<p>
<code>
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
</code>
</p>
</blockquote>
</blockquote>

<h3>27.8.2 C Library files [c.files]</h3>

<p>
Before "See also", add a new paragraph.
</p>
<blockquote>
<p>
The function <code>tmpnam</code>
is not required to avoid data races (17.6.5.7)
if its argument is <code>NULL</code>.
</p>
</blockquote>
</body>
</html>
