-
-
Notifications
You must be signed in to change notification settings - Fork 543
performance: Optimize shared_mutex and fix C++20 modular build errors #7007
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
hkaiser
merged 12 commits into
TheHPXProject:master
from
arpittkhandelwal:optimize-shared-mutex
May 10, 2026
+106
−17
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d5bf3c3
performance: Optimize shared_mutex with lock-free fast paths and stru…
6acdd90
performance: Address maintainer feedback on shared_mutex spin loops a…
arpittkhandelwal 47de6f4
performance: Refine set_state short-circuit and reuse state from fail…
arpittkhandelwal a371a39
performance: Replace all redundant state.load with s=s1 in spin loops
arpittkhandelwal f00d4da
performance: Fix clang-format line wrap in set_state
arpittkhandelwal 13ad2b2
performance: Eliminate redundant atomic refcounts in shared_mutex wra…
arpittkhandelwal 5c3a426
style: Fix clang-format line wrapping
arpittkhandelwal 38d7f22
performance: Final optimized shared_mutex with lifetime safety refcounts
arpittkhandelwal e7605f4
style: Match clang-format requirements for compare_exchange_strong
arpittkhandelwal 1ed78e7
style: fix clang-format issues in shared_mutex.hpp
arpittkhandelwal 81041ec
performance: Simplify unlock_shared and add missing include to benchmark
arpittkhandelwal cb7f0af
style: Fix clang-format issues in shared_mutex.hpp and shared_mutex_o…
arpittkhandelwal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| // (C) Copyright 2026 Arpit Khandelwal | ||
| // | ||
| // SPDX-License-Identifier: BSL-1.0 | ||
| // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
| // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
|
|
||
| #include <hpx/config.hpp> | ||
| #include <hpx/hpx.hpp> | ||
| #include <hpx/hpx_init.hpp> | ||
| #include <hpx/include/util.hpp> | ||
| #include <hpx/modules/testing.hpp> | ||
| #include <hpx/synchronization/shared_mutex.hpp> | ||
|
|
||
| #include <cstdint> | ||
| #include <iostream> | ||
|
hkaiser marked this conversation as resolved.
|
||
| #include <vector> | ||
|
|
||
| std::uint64_t num_iterations = 100000; | ||
| std::uint64_t reader_threads = 4; | ||
|
|
||
| hpx::shared_mutex mtx; | ||
|
|
||
| void reader() | ||
| { | ||
| for (std::uint64_t i = 0; i < num_iterations; ++i) | ||
| { | ||
| std::shared_lock<hpx::shared_mutex> l(mtx); | ||
| } | ||
|
arpittkhandelwal marked this conversation as resolved.
|
||
| } | ||
|
|
||
| int hpx_main(hpx::program_options::variables_map& vm) | ||
| { | ||
| num_iterations = vm["iterations"].as<std::uint64_t>(); | ||
| reader_threads = hpx::get_num_worker_threads(); | ||
|
|
||
| std::cout << "Starting benchmark with " << reader_threads << " threads..." | ||
| << std::endl; | ||
|
|
||
| std::vector<hpx::future<void>> futures; | ||
| futures.reserve(reader_threads); | ||
|
|
||
| hpx::chrono::high_resolution_timer walltime; | ||
|
|
||
| for (std::uint64_t i = 0; i < reader_threads; ++i) | ||
| { | ||
| futures.push_back(hpx::async(&reader)); | ||
| } | ||
|
|
||
| hpx::wait_all(futures); | ||
|
|
||
| double const duration = walltime.elapsed(); | ||
|
|
||
| std::cout << "Total time: " << duration << " seconds" << std::endl; | ||
| std::cout << "Average time per reader thread: " << duration / reader_threads | ||
| << " seconds" << std::endl; | ||
|
|
||
| hpx::util::print_cdash_timing("SharedMutexOverhead", duration); | ||
|
|
||
| return hpx::local::finalize(); | ||
| } | ||
|
|
||
| int main(int argc, char* argv[]) | ||
| { | ||
| hpx::program_options::options_description cmdline( | ||
| "usage: " HPX_APPLICATION_STRING " [options]"); | ||
|
|
||
| cmdline.add_options()("iterations", | ||
| hpx::program_options::value<std::uint64_t>()->default_value(100000), | ||
| "number of iterations per thread"); | ||
|
|
||
| hpx::local::init_params init_args; | ||
| init_args.desc_cmdline = cmdline; | ||
|
|
||
| return hpx::local::init(hpx_main, argc, argv, init_args); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.