<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Change std::call_once to use per-flag lock rather than global lock"
   href="https://bugs.llvm.org/show_bug.cgi?id=44152">44152</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Change std::call_once to use per-flag lock rather than global lock
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>dehuan@motorola.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>In libc++, std::call_once uses a global lock. This seems like a poor design
choice.

Code here:
<a href="https://github.com/llvm/llvm-project/blob/master/libcxx/src/mutex.cpp#L226">https://github.com/llvm/llvm-project/blob/master/libcxx/src/mutex.cpp#L226</a>

Previously MSVC also used global lock but it was changed in 2015:
<a href="https://devblogs.microsoft.com/cppblog/stl-fixes-in-vs-2015-part-2/">https://devblogs.microsoft.com/cppblog/stl-fixes-in-vs-2015-part-2/</a>

More story:
<a href="https://stackoverflow.com/questions/22692783/is-stdcall-once-reentrant-and-thread-safe">https://stackoverflow.com/questions/22692783/is-stdcall-once-reentrant-and-thread-safe</a>
<a href="https://stackoverflow.com/questions/26477070/concurrent-stdcall-once-calls">https://stackoverflow.com/questions/26477070/concurrent-stdcall-once-calls</a>

For scalability, I believe there should be one mutex per std::once_flag.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>