1 //===----------------------------------------------------------------------===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 // 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 13 14 // jthread(jthread&& x) noexcept; 15 16 #include <cassert> 17 #include <stop_token> 18 #include <thread> 19 #include <type_traits> 20 #include <utility> 21 22 #include "make_test_thread.h" 23 #include "test_macros.h" 24 25 static_assert(std::is_nothrow_move_constructible_v<std::jthread>); 26 main(int,char **)27int main(int, char**) { 28 { 29 // x.get_id() == id() and get_id() returns the value of x.get_id() prior 30 // to the start of construction. 31 std::jthread j1 = support::make_test_jthread([] {}); 32 auto id1 = j1.get_id(); 33 34 std::jthread j2(std::move(j1)); 35 assert(j1.get_id() == std::jthread::id()); 36 assert(j2.get_id() == id1); 37 } 38 39 { 40 // ssource has the value of x.ssource prior to the start of construction 41 // and x.ssource.stop_possible() is false. 42 std::jthread j1 = support::make_test_jthread([] {}); 43 auto ss1 = j1.get_stop_source(); 44 45 std::jthread j2(std::move(j1)); 46 assert(ss1 == j2.get_stop_source()); 47 assert(!j1.get_stop_source().stop_possible()); 48 assert(j2.get_stop_source().stop_possible()); 49 } 50 51 return 0; 52 } 53