39 explicit thread(std::thread&& value) noexcept : impl_(std::move(value)) {}
45 template <
typename F,
typename... Args,
47 !std::is_same_v<std::decay_t<F>,
thread> && !std::is_same_v<std::decay_t<F>,
thread_config>,
int> = 0>
48 explicit thread(F&& function, Args&&... args) : impl_(
std::forward<F>(function),
std::forward<Args>(args)...)
58 template <
typename F,
typename... Args>
60 : impl_(make_configured_impl(config,
std::forward<F>(function),
std::forward<Args>(args)...))
74 template <typename F, typename... Args>
80 {
return thread(std::forward<F>(function), std::forward<Args>(args)...); });
89 template <
typename F,
typename... Args>
94 {
return thread(config, std::forward<F>(function), std::forward<Args>(args)...); });
129 return impl_.joinable();
136 return impl_.get_id();
140 [[nodiscard]]
static auto
143 return std::thread::hardware_concurrency();
185 return impl_.set_name(name);
192 return impl_.get_name();
213 return impl_.release();
220 template <
typename F,
typename... Args>
224 auto gate = std::make_shared<detail::thread_start_gate>();
226 [gate, callable =
detail::bind_args(std::forward<F>(function), std::forward<Args>(args)...)]()
mutable
235 gate->release(
false);
238 if (value.joinable())
248 throw std::system_error(configured.error(),
"thread configuration");
255 detail::thread_backend impl_;
C++17 callable and argument binding with move-only support.
auto configure(native_scheduling_config const &config) -> expected< void, std::error_code >
Owning wrapper around std::thread with RAII join-on-destroy semantics.
Strongly-typed nice value in the POSIX range $[-20, 19]$.
Portable thread configuration bundle.
Non-owning view over a running thread or jthread.
Owning thread wrapper with result-based lifecycle/configuration API.
auto detach() -> result< void >
Detach the thread.
auto release() noexcept -> std::thread
Release ownership and return underlying std::thread.
static auto create(thread_config const &config, F &&function, Args &&... args) -> result< thread >
Create configured thread without throwing.
static auto create(F &&function, Args &&... args) -> std::enable_if_t<!std::is_same_v< std::decay_t< F >, thread_config >, result< thread > >
Create thread without throwing.
thread(std::thread &&value) noexcept
Take ownership of an existing std::thread.
auto set_name(std::string const &name) -> result< void >
Set thread name.
thread(thread_config const &config, F &&function, Args &&... args)
Start a thread and apply thread_config before user code runs.
auto set_nice(nice_value value) -> result< void >
Set explicit nice value.
static auto hardware_concurrency() noexcept -> unsigned
Forward std::thread::hardware_concurrency().
auto get_nice() const -> result< nice_value >
Query current nice value.
void detach_or_throw()
Throwing counterpart to detach.
thread(thread &&) noexcept=default
thread(F &&function, Args &&... args)
Start a thread from callable and arguments.
auto set_priority(priority_level level) -> result< void >
Set portable priority preset.
thread()=default
Construct an empty, non-joinable thread object.
void join_or_throw()
Throwing counterpart to join.
auto configure(thread_config const &config) -> result< void >
Apply a full portable thread configuration to the running thread.
auto get_priority() const -> result< priority_level >
Query current portable priority preset.
auto get_name() const -> result< std::string >
Query thread name if supported by platform/backend.
auto get_id() const noexcept -> std::thread::id
Return std::thread id of the owned thread.
auto join() -> result< void >
Join the thread.
auto set_affinity(thread_affinity const &affinity) -> result< void >
Apply CPU affinity set.
auto get_affinity() const -> result< thread_affinity >
Query current CPU affinity.
auto joinable() const noexcept -> bool
Return whether the thread object owns a running thread.
auto set_nice(Control &control, nice_value value) -> result< void >
auto get_affinity(result< native_thread_affinity > affinity) -> result< thread_affinity >
auto set_priority(Control &control, priority_level level) -> result< void >
auto get_priority(result< int > value) -> result< priority_level >
auto get_nice(result< int > value) -> result< nice_value >
auto configure(Control &control, thread_config const &config) -> result< void >
auto set_affinity(Control &control, thread_affinity const &affinity) -> result< void >
void join_or_throw(ThreadLike &value, char const *operation)
void detach_or_throw(ThreadLike &value, char const *operation)
auto detach(ThreadLike &value) -> result< void >
auto join(ThreadLike &value) -> result< void >
auto make_scope_exit(F &&function) -> scope_exit< std::decay_t< F > >
constexpr auto to_native(shutdown_policy policy) noexcept -> shutdown_policy_backend
auto bind_args(F &&function, Args &&... args)
auto try_result(Function &&function) -> decltype(std::forward< Function >(function)())
priority_level
Portable non-realtime priority levels.
expected< T, std::error_code > result
Standard result type used by public APIs.
C++17 thread wrappers and non-owning views.
Portable thread startup and runtime configuration.