brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · e896343 Raw
51 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8//9// UNSUPPORTED: no-threads10// UNSUPPORTED: c++03, c++11, c++14, c++1711 12// jthread(jthread&& x) noexcept;13 14#include <cassert>15#include <stop_token>16#include <thread>17#include <type_traits>18#include <utility>19 20#include "make_test_thread.h"21#include "test_macros.h"22 23static_assert(std::is_nothrow_move_constructible_v<std::jthread>);24 25int main(int, char**) {26  {27    // x.get_id() == id() and get_id() returns the value of x.get_id() prior28    // to the start of construction.29    std::jthread j1 = support::make_test_jthread([] {});30    auto id1        = j1.get_id();31 32    std::jthread j2(std::move(j1));33    assert(j1.get_id() == std::jthread::id());34    assert(j2.get_id() == id1);35  }36 37  {38    // ssource has the value of x.ssource prior to the start of construction39    // and x.ssource.stop_possible() is false.40    std::jthread j1 = support::make_test_jthread([] {});41    auto ss1        = j1.get_stop_source();42 43    std::jthread j2(std::move(j1));44    assert(ss1 == j2.get_stop_source());45    assert(!j1.get_stop_source().stop_possible());46    assert(j2.get_stop_source().stop_possible());47  }48 49  return 0;50}51