[libcxx-commits] [PATCH] D68480: Implementation of C++20's P1135R6 for libcxx

Olivier Giroux via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Oct 4 13:13:36 PDT 2019


__simt__ created this revision.
__simt__ added reviewers: jfb, ldionne, EricWF.
Herald added subscribers: libcxx-commits, dexonsmith, krytarowski, mgorny.

This is the first review of this code so there's a lot to look at, and I'm fully expecting a lot of changes will be requested.

This patch contains...

A) Changes to __threading_support that introduce:

1. Low-level semaphores on POSIX and Apple GCD, and futex on Linux.
2. Declarations for a sharded table of contention state in the dylib, used by atomic::wait.
3. Declarations for a thread_local variable in the dylib, used by barriers.

B) The <atomic> changes from P1135 <https://reviews.llvm.org/P1135>:

1. High QoI: multi-layered back-off, using either/both the state from 1b and futexes from 1a.
2. Low QoI: exponential time back-off, using chrono only.

C) Barrier:

1. High QoI: a tree barrier, using the acceleration state in 1c to amortize the extra round.
2. Low QoI: a central barrier, with a specialization for the empty completion function.

D) Semaphore:

1. All QoI: a general template semaphore for very large ptrdiff_t values.
2. High QoI: a specialization for “reasonable” ptrdiff_t values, using semaphores in 1a and acceleration atomics.
3. Low QoI: a specialization for unit count.

E) Latch:

1. All QoI (low): a central latch. (If there's a desire to see it, I could borrow the same QoI knobs from barrier, but sizeof() would grow a lot.)

F) The first basic tests for each facility from P1135 <https://reviews.llvm.org/P1135>.

G) Miscellaneous tweaks I needed to get this to build as libcu++ (the CUDA variant). We can drop these or you can take them as improvements. One of them is a legit macro bug.


Repository:
  rCXX libc++

https://reviews.llvm.org/D68480

Files:
  include/__config
  include/__threading_support
  include/atomic
  include/barrier
  include/chrono
  include/cstddef
  include/latch
  include/semaphore
  include/stdexcept
  include/type_traits
  src/CMakeLists.txt
  src/atomic.cpp
  src/barrier.cpp
  test/std/atomics/atomics.types.operations/atomics.types.operations.wait/atomic_wait.pass.cpp
  test/std/thread/thread.barrier/arrive.pass.cpp
  test/std/thread/thread.barrier/arrive_and_drop.pass.cpp
  test/std/thread/thread.barrier/arrive_and_wait.pass.cpp
  test/std/thread/thread.barrier/completion.pass.cpp
  test/std/thread/thread.barrier/version.pass.cpp
  test/std/thread/thread.latch/arrive_and_wait.pass.cpp
  test/std/thread/thread.latch/count_down.pass.cpp
  test/std/thread/thread.latch/try_wait.pass.cpp
  test/std/thread/thread.latch/version.pass.cpp
  test/std/thread/thread.semaphore/acquire.pass.cpp
  test/std/thread/thread.semaphore/max.pass.cpp
  test/std/thread/thread.semaphore/release.pass.cpp
  test/std/thread/thread.semaphore/timed.pass.cpp
  test/std/thread/thread.semaphore/try_acquire.pass.cpp
  test/std/thread/thread.semaphore/version.pass.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68480.223270.patch
Type: text/x-patch
Size: 81388 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20191004/12941ec8/attachment-0001.bin>


More information about the libcxx-commits mailing list