From 9b85c38e374bc0fec5562578dc73559adf111e1b Mon Sep 17 00:00:00 2001 From: Christian Mazakas Date: Wed, 22 Mar 2023 10:46:19 -0700 Subject: [PATCH 1/4] Add rehash, add missing move in insert() --- include/boost/unordered/concurrent_flat_map.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/boost/unordered/concurrent_flat_map.hpp b/include/boost/unordered/concurrent_flat_map.hpp index 0be57eef..c21660b8 100644 --- a/include/boost/unordered/concurrent_flat_map.hpp +++ b/include/boost/unordered/concurrent_flat_map.hpp @@ -126,7 +126,7 @@ namespace boost { /// bool insert(value_type const& obj) { return table_.insert(obj); } - bool insert(value_type&& obj) { return table_.insert(obj); } + bool insert(value_type&& obj) { return table_.insert(std::move(obj)); } bool insert(init_type const& obj) { return table_.insert(obj); } bool insert(init_type&& obj) { return table_.insert(std::move(obj)); } @@ -143,6 +143,10 @@ namespace boost { { return table_.visit_all(std::move(f)); } + + /// Hash Policy + /// + void rehash(size_type n) { table_.rehash(n); } }; } // namespace unordered } // namespace boost From e9d9f19e76793b34551ea61da8d80aa962951562 Mon Sep 17 00:00:00 2001 From: Christian Mazakas Date: Wed, 22 Mar 2023 10:47:01 -0700 Subject: [PATCH 2/4] Flesh out insert_tests --- test/cfoa/insert_tests.cpp | 88 ++++++++++++++++++++++++-------------- 1 file changed, 57 insertions(+), 31 deletions(-) diff --git a/test/cfoa/insert_tests.cpp b/test/cfoa/insert_tests.cpp index eb63403b..ea2db80e 100644 --- a/test/cfoa/insert_tests.cpp +++ b/test/cfoa/insert_tests.cpp @@ -188,37 +188,22 @@ namespace { { template void operator()(std::vector& values, X& x) { - std::mutex m; std::vector threads; - std::condition_variable cv; - - auto ready = false; - auto subslices = split(values, num_threads); - BOOST_ASSERT(subslices.size() == num_threads); - for (std::size_t i = 0; i < num_threads; ++i) { - threads.emplace_back([&x, &m, &ready, &subslices, &cv, i] { - std::unique_lock lk(m); - cv.wait(lk, [&] { return ready; }); - lk.unlock(); + threads.emplace_back([&x, &subslices, i] { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); - auto s = subslices[i]; - - for (auto const& r : s) { - bool b = x.insert(r); - (void)b; + { + auto s = subslices[i]; + for (auto const& r : s) { + bool b = x.insert(r); + (void)b; + } } }); } - - { - std::unique_lock lk(m); - ready = true; - } - cv.notify_all(); - for (auto& t : threads) { t.join(); } @@ -229,9 +214,32 @@ namespace { { template void operator()(std::vector& values, X& x) { - for (auto& r : values) { - bool b = x.insert(std::move(r)); - (void)b; + BOOST_TEST_EQ(raii::copy_constructor, 0); + + std::vector threads; + auto subslices = split(values, num_threads); + + for (std::size_t i = 0; i < num_threads; ++i) { + threads.emplace_back([&x, &subslices, i] { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + + { + auto s = subslices[i]; + for (auto& r : s) { + bool b = x.insert(std::move(r)); + (void)b; + } + } + }); + } + for (auto& t : threads) { + t.join(); + } + + if (std::is_same::value) { + BOOST_TEST_EQ(raii::copy_constructor, x.size()); + } else { + BOOST_TEST_EQ(raii::copy_constructor, 0); } } } rvalue_inserter; @@ -240,14 +248,29 @@ namespace { { template void operator()(std::vector& values, X& x) { - x.insert(values.begin(), values.end()); + std::vector threads; + auto subslices = split(values, num_threads); + + for (std::size_t i = 0; i < num_threads; ++i) { + threads.emplace_back([&x, &subslices, i] { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + + { + auto s = subslices[i]; + x.insert(s.begin(), s.end()); + } + }); + } + for (auto& t : threads) { + t.join(); + } } } iterator_range_inserter; template void insert(X*, G gen, F inserter, test::random_generator rg) { - auto values = make_random_values(1024 * 1024, [&] { return gen(rg); }); + auto values = make_random_values(1024 * 16, [&] { return gen(rg); }); BOOST_TEST_GT(values.size(), 0u); auto reference_map = @@ -264,7 +287,10 @@ namespace { using value_type = typename X::value_type; BOOST_TEST_EQ(x.size(), x.visit_all([&](value_type const& kv) { - BOOST_TEST(reference_map.contains(kv.first)); + if (BOOST_TEST(reference_map.contains(kv.first)) && + rg == test::sequential) { + BOOST_TEST_EQ(kv.second, reference_map[kv.first]); + } })); } @@ -286,15 +312,15 @@ namespace { } // namespace using test::default_generator; -using test::generate_collisions; using test::limited_range; +using test::sequential; // clang-format off UNORDERED_TEST( insert, ((map)) ((value_type_generator)(init_type_generator)) ((lvalue_inserter)(rvalue_inserter)(iterator_range_inserter)) - ((default_generator)(limited_range))) + ((default_generator)(sequential)(limited_range))) // clang-format on RUN_TESTS() From 3064801a8904ca650b60c5ab656647ec61d80839 Mon Sep 17 00:00:00 2001 From: Christian Mazakas Date: Wed, 22 Mar 2023 11:19:13 -0700 Subject: [PATCH 3/4] Attempt to add tsan to GHA --- .github/workflows/ci.yml | 9 +++++++++ test/Jamfile.v2 | 2 ++ 2 files changed, 11 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index da3f5b2c..40e6f9a7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -54,6 +54,9 @@ jobs: - { name: Collect coverage, coverage: yes, compiler: gcc-8, cxxstd: '03,11', os: ubuntu-20.04, install: 'g++-8-multilib', address-model: '32,64', ccache_key: "cov" } + - { name: "cfoa tsan (gcc)", cxxstd: '11,14,17,20,2b', os: ubuntu-22.04, compiler: gcc-12, + targets: 'libs/unordered/test//cfoa_tests', thread-sanitize: yes } + # Linux, clang, libc++ - { compiler: clang-7, cxxstd: '03,11,14,17', os: ubuntu-20.04, stdlib: libc++, install: 'clang-7 libc++-7-dev libc++abi-7-dev' } - { compiler: clang-10, cxxstd: '03,11,14,17,20', os: ubuntu-20.04, stdlib: libc++, install: 'clang-10 libc++-10-dev libc++abi-10-dev' } @@ -65,12 +68,16 @@ jobs: compiler: clang-12, cxxstd: '17,20,2b', os: ubuntu-20.04, stdlib: libc++, install: 'clang-12 libc++-12-dev libc++abi-12-dev', ccache_key: "san2" } - { compiler: clang-13, cxxstd: '03,11,14,17,20,2b', os: ubuntu-22.04, stdlib: libc++, install: 'clang-13 libc++-13-dev libc++abi-13-dev' } - { compiler: clang-14, cxxstd: '03,11,14,17,20,2b', os: ubuntu-22.04, stdlib: libc++, install: 'clang-14 libc++-14-dev libc++abi-14-dev' } + # not using libc++ because of https://github.com/llvm/llvm-project/issues/52771 - { name: "clang-14 w/ sanitizers (03,11,14)", sanitize: yes, compiler: clang-14, cxxstd: '03,11,14', os: ubuntu-22.04, ccache_key: "san1" } - { name: "clang-14 w/ sanitizers (17,20,2b)", sanitize: yes, compiler: clang-14, cxxstd: '17,20,2b', os: ubuntu-22.04, ccache_key: "san2" } + - { name: "cfoa tsan (clang)", cxxstd: '11,14,17,20,2b', os: ubuntu-22.04, compiler: clang-14, + targets: 'libs/unordered/test//cfoa_tests', thread-sanitize: yes } + # OSX, clang - { compiler: clang, cxxstd: '03,11,14,17,2a', os: macos-11, } - { compiler: clang, cxxstd: '03,11,14,17,2a', os: macos-12, sanitize: yes } @@ -184,6 +191,8 @@ jobs: B2_COMPILER: ${{matrix.compiler}} B2_CXXSTD: ${{matrix.cxxstd}} B2_SANITIZE: ${{matrix.sanitize}} + B2_TSAN: ${{matrx.thread-sanitize}} + B2_TARGETS: ${{matrix.targets}} B2_STDLIB: ${{matrix.stdlib}} # More entries can be added in the same way, see the B2_ARGS assignment in ci/enforce.sh for the possible keys. # B2_DEFINES: ${{matrix.defines}} diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index f94bc6f6..eb971b37 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -164,3 +164,5 @@ rule build_cfoa ( name ) } build_cfoa insert_tests ; + +alias cfoa_tests : cfoa_insert_tests ; From ff356ac0839d4f8080995b03b8b0eae8358bad88 Mon Sep 17 00:00:00 2001 From: Christian Mazakas Date: Wed, 22 Mar 2023 11:20:03 -0700 Subject: [PATCH 4/4] Fix typo in GHA ci.yml --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 40e6f9a7..f0cf3805 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -191,7 +191,7 @@ jobs: B2_COMPILER: ${{matrix.compiler}} B2_CXXSTD: ${{matrix.cxxstd}} B2_SANITIZE: ${{matrix.sanitize}} - B2_TSAN: ${{matrx.thread-sanitize}} + B2_TSAN: ${{matrix.thread-sanitize}} B2_TARGETS: ${{matrix.targets}} B2_STDLIB: ${{matrix.stdlib}} # More entries can be added in the same way, see the B2_ARGS assignment in ci/enforce.sh for the possible keys.