1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: no-threads
10 // UNSUPPORTED: libcpp-has-no-experimental-stop_token
11 // UNSUPPORTED: c++03, c++11, c++14, c++17
12 // XFAIL: availability-synchronization_library-missing
14 // friend void swap(jthread& x, jthread& y) noexcept;
18 #include <type_traits>
20 #include "make_test_thread.h"
21 #include "test_macros.h"
24 concept IsFreeSwapNoexcept
= requires(T
& a
, T
& b
) {
25 { swap(a
, b
) } noexcept
;
28 static_assert(IsFreeSwapNoexcept
<std::jthread
>);
30 int main(int, char**) {
31 // x is default constructed
34 std::jthread t2
= support::make_test_jthread([] {});
35 const auto originalId2
= t2
.get_id();
38 assert(t1
.get_id() == originalId2
);
39 assert(t2
.get_id() == std::jthread::id());
42 // y is default constructed
44 std::jthread t1
= support::make_test_jthread([] {});
46 const auto originalId1
= t1
.get_id();
49 assert(t1
.get_id() == std::jthread::id());
50 assert(t2
.get_id() == originalId1
);
53 // both not default constructed
55 std::jthread t1
= support::make_test_jthread([] {});
56 std::jthread t2
= support::make_test_jthread([] {});
57 const auto originalId1
= t1
.get_id();
58 const auto originalId2
= t2
.get_id();
61 assert(t1
.get_id() == originalId2
);
62 assert(t2
.get_id() == originalId1
);
65 // both default constructed
71 assert(t1
.get_id() == std::jthread::id());
72 assert(t2
.get_id() == std::jthread::id());