Skip to content

Commit 78dc936

Browse files
committed
Updated list of supported implementations
Changed status to "Under development and not yet ready for production use". Updated Compiler Explorer example to not use std::jthread since that is missing in libc++ and to not use chrono operator<< overloads to display durations since some of the older implementations that this library support have not implemented those overloads. Made the same adjustments to the test and example code. Updated the CI workflows so they don't try to use ThreadSanitizer when using libstdc++ versions that won't compile when using std::timed_mutex. Also removed compiling in C++17 mode for now. It should be be easy to replace the concepts with old-school type traits if needed. Signed-off-by: Ted Lyngmo <[email protected]>
1 parent 3a595f9 commit 78dc936

File tree

4 files changed

+58
-39
lines changed

4 files changed

+58
-39
lines changed

.github/workflows/ci_tests.yml

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,29 @@ jobs:
4242
"tests": [
4343
{ "stdlibs": ["libstdc++"],
4444
"tests": [
45-
"Debug.Default", "Release.Default", "Release.TSan",
45+
"Debug.Default", "Release.Default",
4646
"Release.MaxSan", "Debug.Werror", "Debug.Dynamic",
4747
"Debug.Coverage"
4848
]
4949
}
5050
]
5151
},
52-
{ "cxxversions": ["c++23", "c++20", "c++17"],
52+
{ "cxxversions": ["c++23", "c++20"],
5353
"tests": [{ "stdlibs": ["libstdc++"], "tests": ["Release.Default"]}]
5454
}
5555
]
5656
},
5757
{ "versions": ["14", "13"],
5858
"tests": [
59-
{ "cxxversions": ["c++26", "c++23", "c++20", "c++17"],
59+
{ "cxxversions": ["c++26", "c++23", "c++20"],
6060
"tests": [{ "stdlibs": ["libstdc++"], "tests": ["Release.Default"]}]
6161
}
6262
]
6363
},
6464
{
6565
"versions": ["12", "11"],
6666
"tests": [
67-
{ "cxxversions": ["c++23", "c++20", "c++17"],
67+
{ "cxxversions": ["c++23", "c++20"],
6868
"tests": [{ "stdlibs": ["libstdc++"], "tests": ["Release.Default"]}]
6969
}
7070
]
@@ -75,15 +75,21 @@ jobs:
7575
"tests": [
7676
{"cxxversions": ["c++26"],
7777
"tests": [
78-
{ "stdlibs": ["libstdc++", "libc++"],
78+
{ "stdlibs": ["libc++"],
7979
"tests": [
8080
"Debug.Default", "Release.Default", "Release.TSan",
8181
"Release.MaxSan", "Debug.Werror", "Debug.Dynamic"
8282
]
83+
},
84+
{ "stdlibs": ["libstdc++"],
85+
"tests": [
86+
"Debug.Default", "Release.Default",
87+
"Release.MaxSan", "Debug.Werror", "Debug.Dynamic"
88+
]
8389
}
8490
]
8591
},
86-
{ "cxxversions": ["c++23", "c++20", "c++17"],
92+
{ "cxxversions": ["c++23", "c++20"],
8793
"tests": [
8894
{"stdlibs": ["libstdc++", "libc++"], "tests": ["Release.Default"]}
8995
]
@@ -92,7 +98,7 @@ jobs:
9298
},
9399
{ "versions": ["20", "19", "18"],
94100
"tests": [
95-
{ "cxxversions": ["c++26", "c++23", "c++20", "c++17"],
101+
{ "cxxversions": ["c++26", "c++23", "c++20"],
96102
"tests": [
97103
{"stdlibs": ["libstdc++", "libc++"], "tests": ["Release.Default"]}
98104
]
@@ -101,10 +107,10 @@ jobs:
101107
},
102108
{ "versions": ["17"],
103109
"tests": [
104-
{ "cxxversions": ["c++26", "c++23", "c++20", "c++17"],
110+
{ "cxxversions": ["c++26", "c++23", "c++20"],
105111
"tests": [{"stdlibs": ["libc++"], "tests": ["Release.Default"]}]
106112
},
107-
{ "cxxversions": ["c++20", "c++17"],
113+
{ "cxxversions": ["c++20"],
108114
"tests": [{"stdlibs": ["libstdc++"], "tests": ["Release.Default"]}]
109115
}
110116
]
@@ -113,7 +119,7 @@ jobs:
113119
"appleclang": [
114120
{ "versions": ["latest"],
115121
"tests": [
116-
{ "cxxversions": ["c++26", "c++23", "c++20", "c++17"],
122+
{ "cxxversions": ["c++26", "c++23", "c++20"],
117123
"tests": [{ "stdlibs": ["libc++"], "tests": ["Release.Default"]}]
118124
}
119125
]

README.md

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ SPDX-License-Identifier: MIT
55
-->
66

77
<!-- markdownlint-disable-next-line line-length -->
8-
![Library Status](https://raw.githubusercontent.com/bemanproject/beman/refs/heads/main/images/badges/beman_badge-beman_library_production_ready_api_may_undergo_changes.svg) ![Continuous Integration Tests](https://github.com/bemanproject/timed_lock_alg/actions/workflows/ci_tests.yml/badge.svg) ![Lint Check (pre-commit)](https://github.com/bemanproject/timed_lock_alg/actions/workflows/pre-commit-check.yml/badge.svg) [![Coverage](https://coveralls.io/repos/github/bemanproject/timed_lock_alg/badge.svg?branch=main)](https://coveralls.io/github/bemanproject/timed_lock_alg?branch=main) ![Standard Target](https://github.com/bemanproject/beman/blob/main/images/badges/cpp29.svg) [![Compiler Explorer Example](https://img.shields.io/badge/Try%20it%20on%20Compiler%20Explorer-grey?logo=compilerexplorer&logoColor=67c52a)](https://godbolt.org/z/3reh77M53)
8+
![Library Status](https://github.com/bemanproject/beman/blob/main/images/badges/beman_badge-beman_library_under_development.svg) ![Continuous Integration Tests](https://github.com/bemanproject/timed_lock_alg/actions/workflows/ci_tests.yml/badge.svg) ![Lint Check (pre-commit)](https://github.com/bemanproject/timed_lock_alg/actions/workflows/pre-commit-check.yml/badge.svg) [![Coverage](https://coveralls.io/repos/github/bemanproject/timed_lock_alg/badge.svg?branch=main)](https://coveralls.io/github/bemanproject/timed_lock_alg?branch=main) ![Standard Target](https://github.com/bemanproject/beman/blob/main/images/badges/cpp29.svg) [![Compiler Explorer Example](https://img.shields.io/badge/Try%20it%20on%20Compiler%20Explorer-grey?logo=compilerexplorer&logoColor=67c52a)](https://godbolt.org/z/jPYdxT3E7)
99

1010
`beman.timed_lock_alg` implements timed lock algorithms for multiple lockables.
1111

1212
**Implements**: `std::try_lock_until` and `std::try_lock_for` proposed in [Timed lock algorithms for multiple lockables (P3832R0)](https://wg21.link/P3832R0).
1313

14-
**Status**: [Production ready. API may undergo changes.](https://github.com/bemanproject/beman/blob/main/docs/beman_library_maturity_model.md#production-ready-api-may-undergo-changes)
14+
**Status**: [Under development and not yet ready for production use.](https://github.com/bemanproject/beman/blob/main/docs/beman_library_maturity_model.md#under-development-and-not-yet-ready-for-production-use)
1515

1616
## License
1717

@@ -49,30 +49,16 @@ You can disable building tests by setting CMake option
4949
[`BEMAN_TIMED_LOCK_ALG_BUILD_TESTS`](#beman_timed_lock_alg_build_tests) to `OFF`
5050
when configuring the project.
5151

52-
> [!TIP]
53-
>
54-
> The logs indicate examples disabled due to lack of compiler support.
55-
>
56-
> For example:
57-
>
58-
> ```txt
59-
> -- Looking for __cpp_lib_ranges
60-
> -- Looking for __cpp_lib_ranges - not found
61-
> CMake Warning at examples/CMakeLists.txt:12 (message):
62-
> Missing range support! Skip: identity_as_default_projection
63-
>
64-
>
65-
> Examples to be built: identity_direct_usage
66-
> ```
67-
6852
### Supported Platforms
6953

7054
This project officially supports:
7155

72-
* GCC versions 11–15
73-
* LLVM Clang++ (with libstdc++ or libc++) versions 17–21
56+
* GCC versions 10–15
57+
* LLVM Clang++ (with libstdc++ or libc++) versions 11–21
58+
* ICX (with libstdc++ or libc++) versions 2021.1.2-2025.2.1
7459
* AppleClang version 17.0.0 (i.e., the [latest version on GitHub-hosted macOS runners](https://github.com/actions/runner-images/blob/main/images/macos/macos-15-arm64-Readme.md))
75-
* MSVC version 19.44.35215.0 (i.e., the [latest version on GitHub-hosted Windows runners](https://github.com/actions/runner-images/blob/main/images/windows/Windows2022-Readme.md))
60+
* MSVC version 19.29 (with `/std:c++latest`) and 19.30 to 19.44.35215.0 (i.e., the [latest version on GitHub-hosted Windows runners](https://github.com/actions/runner-images/blob/main/images/windows/Windows2022-Readme.md))
61+
* Note: libstdc++ versions 14-14.3 and 15-15.2 (inclusive) does _not_ support using `-fsanitize=thread` on code using `std::timed_mutex` due to [Bug 121496](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121496). This affects GCC and all implementations using libstdc++ such as LLVM Clang++ and ICX unless `-stdlib=libc++` is used.
7662

7763
> [!NOTE]
7864
>

examples/try_lock_a_bunch.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@
99
#include <iostream>
1010
#include <thread>
1111

12+
namespace {
13+
// joining thread for implementations missing std::jthread
14+
class JThread : public std::thread {
15+
public:
16+
template <class... Args>
17+
JThread(Args&&... args) : std::thread(std::forward<Args>(args)...) {}
18+
~JThread() {
19+
if (joinable()) {
20+
join();
21+
}
22+
}
23+
};
24+
} // namespace
25+
1226
namespace tla = beman::timed_lock_alg;
1327

1428
constexpr std::chrono::milliseconds yield(10);
@@ -25,23 +39,24 @@ int main() {
2539
for (int ms = 10; ms <= 70; ms += 20) { // try 10, 30, 50, 70 ms
2640
std::chrono::milliseconds cms(ms);
2741
// start a thread that locks the last mutex unless mtxs is empty
28-
std::jthread jt = [&]() -> std::jthread {
42+
JThread jt = [&]() -> JThread {
2943
if constexpr (not mtxs.empty()) {
30-
return std::jthread(foo, std::ref(mtxs.back()));
44+
return JThread(foo, std::ref(mtxs.back()));
3145
} else {
3246
return {};
3347
}
3448
}();
3549
std::this_thread::sleep_for(yield);
3650

37-
std::cout << "trying for " << cms << '\n';
51+
std::cout << "trying for " << cms.count() << "ms\n";
3852

3953
auto start = std::chrono::steady_clock::now();
4054
auto r1 = std::apply([&](auto&... mxs) { return tla::try_lock_for(cms, mxs...); }, mtxs);
4155
auto end = std::chrono::steady_clock::now();
4256

4357
// should be done in approx. 10, 30, 40 and 40 ms, where the two last tries succeeds:
44-
std::cout << "done in " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start) << ": ";
58+
std::cout << "done in " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()
59+
<< "ms: ";
4560

4661
if (r1 == -1) {
4762
auto sl = std::apply([&](auto&... mxs) { return std::scoped_lock(std::adopt_lock, mxs...); }, mtxs);

tests/beman/timed_lock_alg/mutex.test.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ using namespace std::chrono_literals;
1414
namespace tla = beman::timed_lock_alg;
1515

1616
namespace {
17+
// joining thread for implementations missing std::jthread
18+
class JThread : public std::thread {
19+
public:
20+
template <class... Args>
21+
JThread(Args&&... args) : std::thread(std::forward<Args>(args)...) {}
22+
~JThread() {
23+
if (joinable()) {
24+
join();
25+
}
26+
}
27+
};
1728
const auto now = std::chrono::steady_clock::now();
1829
const auto no_duration = std::chrono::milliseconds{0};
1930

@@ -50,7 +61,7 @@ TEST(Mutex, try_many_unlocked) {
5061

5162
TEST(Mutex, try_many_one_locked) {
5263
std::array<std::timed_mutex, 30> mtxs;
53-
auto th = std::jthread([&] {
64+
auto th = JThread([&] {
5465
std::lock_guard lg(mtxs.back());
5566
std::this_thread::sleep_for(15ms);
5667
});
@@ -63,7 +74,7 @@ TEST(Mutex, try_many_one_locked) {
6374

6475
TEST(Mutex, return_last_failed) {
6576
std::array<std::timed_mutex, 2> mtxs;
66-
auto th = std::jthread([&] {
77+
auto th = JThread([&] {
6778
std::lock(mtxs[0], mtxs[1]);
6879
std::this_thread::sleep_for(10ms);
6980
mtxs[0].unlock(); // 5ms after try_lock_for started, 15ms left
@@ -82,7 +93,7 @@ TEST(Mutex, succeed_with_three_in_tricky_sequence) {
8293
// A different implementation may behave differently but should
8394
// still succeed in locking all three in time.
8495
std::array<std::timed_mutex, 3> mtxs;
85-
auto th = std::jthread([&] {
96+
auto th = JThread([&] {
8697
std::lock(mtxs[0], mtxs[1], mtxs[2]);
8798
std::this_thread::sleep_for(10ms);
8899
mtxs[0].unlock(); // 5ms after try_lock_for started, 15ms left
@@ -97,5 +108,6 @@ TEST(Mutex, succeed_with_three_in_tricky_sequence) {
97108
});
98109

99110
std::this_thread::sleep_for(5ms);
100-
EXPECT_EQ(-1, std::apply([](auto&... mts) { return tla::try_lock_for(20ms, mts...); }, mtxs));
111+
// 20ms is enough for most implementations, but lets give MSVC 10ms more
112+
EXPECT_EQ(-1, std::apply([](auto&... mts) { return tla::try_lock_for(20ms + 10ms, mts...); }, mtxs));
101113
}

0 commit comments

Comments
 (0)