[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / thread / thread.stoptoken / stoptoken / stop_possible.pass.cpp
blobfd73f5e5166782033a33daa8c2c293adf28db17d
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
14 // [[nodiscard]] bool stop_possible() const noexcept;
15 // Returns: false if:
16 // - *this does not have ownership of a stop state, or
17 // - a stop request was not made and there are no associated stop_source objects;
18 // otherwise, true.
20 #include <cassert>
21 #include <concepts>
22 #include <optional>
23 #include <stop_token>
24 #include <type_traits>
26 #include "make_test_thread.h"
27 #include "test_macros.h"
29 template <class T>
30 concept IsStopPossibleNoexcept = requires(const T& t) {
31 { t.stop_possible() } noexcept;
34 static_assert(IsStopPossibleNoexcept<std::stop_token>);
36 int main(int, char**) {
37 // no state
39 const std::stop_token st;
40 assert(!st.stop_possible());
43 // a stop request was not made and there are no associated stop_source objects
45 std::optional<std::stop_source> ss{std::in_place};
46 const auto st = ss->get_token();
47 ss.reset();
49 assert(!st.stop_possible());
52 // a stop request was not made, but there is an associated stop_source objects
54 std::stop_source ss;
55 const auto st = ss.get_token();
56 assert(st.stop_possible());
59 // a stop request was made and there are no associated stop_source objects
61 std::optional<std::stop_source> ss{std::in_place};
62 const auto st = ss->get_token();
63 ss->request_stop();
64 ss.reset();
66 assert(st.stop_possible());
69 // a stop request was made and there is an associated stop_source objects
71 std::stop_source ss;
72 const auto st = ss.get_token();
73 ss.request_stop();
74 assert(st.stop_possible());
77 // a stop request was made on a different thread and
78 // there are no associated stop_source objects
80 std::optional<std::stop_source> ss{std::in_place};
81 const auto st = ss->get_token();
83 std::thread t = support::make_test_thread([&]() {
84 ss->request_stop();
85 ss.reset();
86 });
88 assert(st.stop_possible());
89 t.join();
90 assert(st.stop_possible());
94 return 0;