<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1526: C++ should not impose thread safety requirements on C99 library implementations</title>
<meta property="og:title" content="Issue 1526: C++ should not impose thread safety requirements on C99 library implementations">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1526.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#Resolved">Resolved</a> status.</em></p>
<h3 id="1526"><a href="lwg-defects.html#1526">1526</a>. C++ should not impose thread safety requirements on C99 library implementations</h3>
<p><b>Section:</b> 16.4.6.10 <a href="https://wg21.link/res.on.data.races">[res.on.data.races]</a> <b>Status:</b> <a href="lwg-active.html#Resolved">Resolved</a>
 <b>Submitter:</b> BSI <b>Opened:</b> 2011-03-24 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>3
</p>
<p><b>View other</b> <a href="lwg-index-open.html#res.on.data.races">active issues</a> in [res.on.data.races].</p>
<p><b>View all other</b> <a href="lwg-index.html#res.on.data.races">issues</a> in [res.on.data.races].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>
<p><b>Addresses GB-111</b></p>

<p>Section 16.4.6.10 <a href="https://wg21.link/res.on.data.races">[res.on.data.races]</a>, Data Race Avoidance, requires the C++ Standard Library to avoid data races 
that might otherwise result from two threads making calls to C++ Standard Library functions on 
distinct objects. The C standard library is part of the C++ Standard Library and some C++ Standary library 
functions (parts of the Localization library, as well as Numeric Conversions in 21.5), are specified 
to make use of the C standard library. Therefore, the C++ standard indirectly imposes a requirement 
on the thread safety of the C standard library. However, since the C standard does not address the 
concept of thread safety conforming C implementations exist that do no provide such guarantees. 
This conflict needs to be reconciled.</p>

<p>Suggested resolution by national body comment:</p>

<blockquote><p>
remove the requirement to make use of <code>strtol()</code> and <code>sprintf()</code> since these functions depend on the 
global C locale and thus cannot be made thread safe.
</p></blockquote>

<p><i>[2011-03-24 Madrid meeting]</i></p>


<p>Deferred</p>

<p><i>[
2011 Bloomington
]</i></p>

<p>
Alisdair: PJ, does this cause a problem in C?
</p>
<p>
PJ: Every implementation know of is thread safe.
</p>
<p>
Pete: There a couple of effects that are specified on strtol() and sprintf() which is a problem.
</p>
<p>
PJ: When C++ talks about C calls it should be "as if" calling the function.
</p>
<p>
Pete: Culprit is to string stuff. My fault.
</p>
<p>
PJ: Not your fault. You did what you were told. Distinct resolution to change wording.
</p>
<p>
Dietmar: What would we break if we change it back?
</p>
<p>
Pete: Nothing. If implemented on top of thread safe C library you are just fine.
</p>
<p>
Alisdair: Anyone want to clean up wording and put it back to what Pete gave us?
</p>
<p>
Alisdair: No volunteers. Do we want to mark as NAD? We could leave it as deferred.
</p>
<p>
Stefanus: Did original submitter care about this?
</p>
<p>
Lawrence: There is some work to make local calls thread safe. The resolution would be to call those thread safe version.
</p>
<p>
Pete: "As if called under single threaded C program"
</p>
<p>
<b>Action Item</b> (Alisdair): Write wording for this issue.
</p>

<p><i>[2012, Kona]</i></p>

<p>
Re-opened at the request of the concurrency subgroup, who feel there is an issue that needs
clarifying for the (planned) 2017 standard.
</p>

<p><b>Rationale:</b></p><p>No consensus to make a change at this time</p>

<p><i>[2012, Portland]</i></p>

<p>
The concurrency subgroup decided to encourage the LWG to consider a change to 16.2 <a href="https://wg21.link/library.c">[library.c]</a> or thereabouts 
to clarify that we are requiring C++-like thread-safety for <code>setlocale</code>, so that races are not introduced 
by C locale accesses, even when the C library allows it. This would require e.g. adding "and data race avoidance" 
at the end of 16.2 <a href="https://wg21.link/library.c">[library.c]</a> p1:
</p>
<p>
"The C++ standard library also makes available the facilities of the C standard library, suitably adjusted to 
ensure static type safety <ins>and data race avoidance</ins>.",
</p>
<p>
with some further clarifications in the sections mentioned in <a href="lwg-defects.html#1526" title="C++ should not impose thread safety requirements on C99 library implementations (Status: Resolved)">1526</a><sup><a href="https://cplusplus.github.io/LWG/issue1526" title="Latest snapshot">(i)</a></sup>.
</p>
<p>
This seems to be consistent with existing implementations. This would technically not be constraining C implementation, 
but it would be further constraining C libraries used for both C and C++.
</p>

<p><i>[Lenexa 2015-05-05: Move to Resolved]</i></p>

<p>JW: it's a bit odd that the issue title says sould not impose requirements on C libs, then the P/R does exactly that. Does make sense though, previously we imposed an implicit requirement which would not have been met. Now we say it explicitly and require it is met.</p>
<p>STL: I think this is Resolved, it has been fixed in the working paper [support.runtime]/6 is an example where we call out where things can race. That implies that for everything else they don't create races.</p>
<p>JW: I'm not sure, I think we still need the "and data race avoidance" to clarify that the features from C avoid races, even though C99 says no such thing.</p>
<p>STL: [library.c] says that something like sqrt is part of the C++ Standard LIbrary. [res.on.data.races] then applies to them. Would be OK with a note there, but am uncomfortable with "and data race avoidance" which sounds like it's making a very strong guarantee.</p>
<p>ACTION ITEM JW to editorially add note to [library.c] p1: "Unless otherwise specified, the C Standard Library functions shall meet the requirements for data race avoidance (xref [res.on.data.races])"</p>
<p>Move to Resolved?</p>
<p>10 in favor, 0 opposed, 3 abstentions</p>


<p id="res-1526"><b>Proposed resolution:</b></p>
<p>This wording is relative to N3376.</p>

<ol>
<li><p>Change 16.2 <a href="https://wg21.link/library.c">[library.c]</a> p1 as indicated:</p>

<blockquote><p>
-1- The C++ standard library also makes available the facilities of the C standard library, suitably adjusted to
ensure static type safety <ins>and data race avoidance</ins>.
</p></blockquote>
</li>
</ol>






</body>
</html>
