brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · 82f2bd2 Raw
45 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// [[nodiscard]] bool request_stop() noexcept;13 14#include <cassert>15#include <concepts>16#include <stop_token>17#include <thread>18#include <type_traits>19 20#include "make_test_thread.h"21#include "test_macros.h"22 23static_assert(noexcept(std::declval<std::jthread&>().request_stop()));24 25int main(int, char**) {26  // Represents a thread27  {28    std::jthread jt = support::make_test_jthread([] {});29    auto st         = jt.get_stop_token();30    assert(!st.stop_requested());31    std::same_as<bool> decltype(auto) result = jt.request_stop();32    assert(result);33    assert(st.stop_requested());34  }35 36  // Does not represent a thread37  {38    std::jthread jt{};39    std::same_as<bool> decltype(auto) result = jt.request_stop();40    assert(!result);41  }42 43  return 0;44}45