2 //===----------------------------------------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP_THREAD
11 #define _LIBCPP_THREAD
24 typedef pthread_t native_handle_type;
27 template <class F, class ...Args> explicit thread(F&& f, Args&&... args);
30 thread(const thread&) = delete;
31 thread(thread&& t) noexcept;
33 thread& operator=(const thread&) = delete;
34 thread& operator=(thread&& t) noexcept;
36 void swap(thread& t) noexcept;
38 bool joinable() const noexcept;
41 id get_id() const noexcept;
42 native_handle_type native_handle();
44 static unsigned hardware_concurrency() noexcept;
47 void swap(thread& x, thread& y) noexcept;
55 bool operator==(thread::id x, thread::id y) noexcept;
56 bool operator!=(thread::id x, thread::id y) noexcept; // removed in C++20
57 bool operator< (thread::id x, thread::id y) noexcept; // removed in C++20
58 bool operator<=(thread::id x, thread::id y) noexcept; // removed in C++20
59 bool operator> (thread::id x, thread::id y) noexcept; // removed in C++20
60 bool operator>=(thread::id x, thread::id y) noexcept; // removed in C++20
61 strong_ordering operator<=>(thread::id x, thread::id y) noexcept; // C++20
63 template<class charT, class traits>
64 basic_ostream<charT, traits>&
65 operator<<(basic_ostream<charT, traits>& out, thread::id id);
68 struct formatter<thread::id, charT>;
73 thread::id get_id() noexcept;
75 void yield() noexcept;
77 template <class Clock, class Duration>
78 void sleep_until(const chrono::time_point<Clock, Duration>& abs_time);
80 template <class Rep, class Period>
81 void sleep_for(const chrono::duration<Rep, Period>& rel_time);
89 #include <__assert> // all public C++ headers provide the assertion handler
90 #include <__availability>
92 #include <__thread/formatter.h>
93 #include <__thread/jthread.h>
94 #include <__thread/this_thread.h>
95 #include <__thread/thread.h>
96 #include <__threading_support>
99 // standard-mandated includes
104 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
105 # pragma GCC system_header
108 #ifdef _LIBCPP_HAS_NO_THREADS
109 # error "<thread> is not supported since libc++ has been configured without support for threads."
112 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES)
119 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
123 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
125 # include <functional>
127 # include <system_error>
128 # include <type_traits>
131 #endif // _LIBCPP_THREAD