brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · ce06d7e Raw
53 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 joinable() const noexcept;13 14#include <atomic>15#include <cassert>16#include <concepts>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<const std::jthread&>().joinable()));24 25int main(int, char**) {26  // Default constructed27  {28    const std::jthread jt;29    std::same_as<bool> decltype(auto) result = jt.joinable();30    assert(!result);31  }32 33  // Non-default constructed34  {35    const std::jthread jt                    = support::make_test_jthread([] {});36    std::same_as<bool> decltype(auto) result = jt.joinable();37    assert(result);38  }39 40  // Non-default constructed41  // the thread of execution has not finished42  {43    std::atomic_bool done                    = false;44    const std::jthread jt                    = support::make_test_jthread([&done] { done.wait(false); });45    std::same_as<bool> decltype(auto) result = jt.joinable();46    done                                     = true;47    done.notify_all();48    assert(result);49  }50 51  return 0;52}53