[libcxx-commits] [PATCH] D149381: [libc++][PSTL] Implement std::for_each{, _n}

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Apr 28 08:21:16 PDT 2023


ldionne accepted this revision.
ldionne added inline comments.
This revision is now accepted and ready to land.


================
Comment at: libcxx/include/__algorithm/for_each.h:22-24
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _Function for_each(_InputIterator __first,
-                                                                                  _InputIterator __last,
-                                                                                  _Function __f) {
----------------
I don't think these formatting changes are necessary here.


================
Comment at: libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/pstl.for_each.pass.cpp:41
+      std::vector<int> a(size);
+      std::vector<bool> called(size); // TODO: does using vector<bool> result in a potential data race?
+      std::for_each(policy, Iter(std::data(a)), Iter(std::data(a) + std::size(a)), [&](int& v) {
----------------
I think it does, cause it's a bit reference under the hood and so for example `begin()`, `begin() + 1` will share the same underlying byte but can be processed in different threads. So yeah, I think `vector<bool>` + pstl is not a happy combination.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149381/new/

https://reviews.llvm.org/D149381



More information about the libcxx-commits mailing list