[libcxx-commits] [libcxx] [libc++] Make sure all `jthread` tests use `support::make_test_jthread`. (PR #70271)
Konstantin Varlamov via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Oct 25 17:34:04 PDT 2023
https://github.com/var-const updated https://github.com/llvm/llvm-project/pull/70271
>From 7ae33c19e0d9f68b1d56be0ad5d99337f394a3e1 Mon Sep 17 00:00:00 2001
From: Konstantin Varlamov <varconsteq at gmail.com>
Date: Wed, 25 Oct 2023 17:01:28 -0700
Subject: [PATCH 1/2] [libc++] Make sure all `jthread` tests use
`support::make_test_jthread`.
---
.../thread.jthread/cons.func.token.pass.cpp | 48 ++++++++++---------
1 file changed, 26 insertions(+), 22 deletions(-)
diff --git a/libcxx/test/std/thread/thread.jthread/cons.func.token.pass.cpp b/libcxx/test/std/thread/thread.jthread/cons.func.token.pass.cpp
index 2d029271d75ce84..fafd7818620aa7d 100644
--- a/libcxx/test/std/thread/thread.jthread/cons.func.token.pass.cpp
+++ b/libcxx/test/std/thread/thread.jthread/cons.func.token.pass.cpp
@@ -19,6 +19,7 @@
#include <thread>
#include <type_traits>
+#include "make_test_thread.h"
#include "test_macros.h"
template <class... Args>
@@ -46,7 +47,7 @@ int main(int, char**) {
// Postconditions: get_id() != id() is true and ssource.stop_possible() is true
// and *this represents the newly started thread.
{
- std::jthread jt{[] {}};
+ std::jthread jt = support::make_test_jthread([] {});
assert(jt.get_stop_source().stop_possible());
assert(jt.get_id() != std::jthread::id());
}
@@ -56,12 +57,13 @@ int main(int, char**) {
// if that expression is well-formed,
{
int result = 0;
- std::jthread jt{[&result](std::stop_token st, int i) {
- assert(st.stop_possible());
- assert(!st.stop_requested());
- result += i;
- },
- 5};
+ std::jthread jt = support::make_test_jthread(
+ [&result](std::stop_token st, int i) {
+ assert(st.stop_possible());
+ assert(!st.stop_requested());
+ result += i;
+ },
+ 5);
jt.join();
assert(result == 5);
}
@@ -70,7 +72,7 @@ int main(int, char**) {
// invoke(auto(std::forward<F>(f)), auto(std::forward<Args>(args))...)
{
int result = 0;
- std::jthread jt{[&result](int i) { result += i; }, 5};
+ std::jthread jt = support::make_test_jthread([&result](int i) { result += i; }, 5);
jt.join();
assert(result == 5);
}
@@ -90,20 +92,22 @@ int main(int, char**) {
auto mainThread = std::this_thread::get_id();
TrackThread arg1;
- std::jthread jt1{[mainThread](const TrackThread& arg) {
- assert(arg.threadId == mainThread);
- assert(arg.threadId != std::this_thread::get_id());
- assert(arg.copyConstructed);
- },
- arg1};
+ std::jthread jt1 = support::make_test_jthread(
+ [mainThread](const TrackThread& arg) {
+ assert(arg.threadId == mainThread);
+ assert(arg.threadId != std::this_thread::get_id());
+ assert(arg.copyConstructed);
+ },
+ arg1);
TrackThread arg2;
- std::jthread jt2{[mainThread](const TrackThread& arg) {
- assert(arg.threadId == mainThread);
- assert(arg.threadId != std::this_thread::get_id());
- assert(arg.moveConstructed);
- },
- std::move(arg2)};
+ std::jthread jt2 = support::make_test_jthread(
+ [mainThread](const TrackThread& arg) {
+ assert(arg.threadId == mainThread);
+ assert(arg.threadId != std::this_thread::get_id());
+ assert(arg.moveConstructed);
+ },
+ std::move(arg2));
}
#if !defined(TEST_HAS_NO_EXCEPTIONS)
@@ -120,7 +124,7 @@ int main(int, char**) {
};
ThrowOnCopyFunc f1;
try {
- std::jthread jt{f1};
+ std::jthread jt = support::make_test_jthread(f1);
assert(false);
} catch (const Exception& e) {
assert(e.threadId == std::this_thread::get_id());
@@ -140,7 +144,7 @@ int main(int, char**) {
};
Arg arg(flag);
- std::jthread jt(
+ std::jthread jt = support::make_test_jthread(
[&flag](const auto&) {
assert(flag == 5); // happens-after the copy-construction of arg
},
>From 53c55bb909f3c3e2da4161b978d118b18714e21b Mon Sep 17 00:00:00 2001
From: Konstantin Varlamov <varconsteq at gmail.com>
Date: Wed, 25 Oct 2023 17:32:44 -0700
Subject: [PATCH 2/2] clang-format
---
.../test/std/thread/thread.jthread/cons.func.token.pass.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libcxx/test/std/thread/thread.jthread/cons.func.token.pass.cpp b/libcxx/test/std/thread/thread.jthread/cons.func.token.pass.cpp
index fafd7818620aa7d..6a445bd5af3208e 100644
--- a/libcxx/test/std/thread/thread.jthread/cons.func.token.pass.cpp
+++ b/libcxx/test/std/thread/thread.jthread/cons.func.token.pass.cpp
@@ -56,7 +56,7 @@ int main(int, char**) {
// invoke(auto(std::forward<F>(f)), get_stop_token(), auto(std::forward<Args>(args))...)
// if that expression is well-formed,
{
- int result = 0;
+ int result = 0;
std::jthread jt = support::make_test_jthread(
[&result](std::stop_token st, int i) {
assert(st.stop_possible());
@@ -71,7 +71,7 @@ int main(int, char**) {
// otherwise
// invoke(auto(std::forward<F>(f)), auto(std::forward<Args>(args))...)
{
- int result = 0;
+ int result = 0;
std::jthread jt = support::make_test_jthread([&result](int i) { result += i; }, 5);
jt.join();
assert(result == 5);
More information about the libcxx-commits
mailing list