|
guts
|
Fallback RAII "join-on-destruction" thread wrapper. More...
#include <gthreads.h>
Public Member Functions | |
| jthread_alias () noexcept=default | |
| Construct an empty (non-joinable) wrapper. | |
| template<class F , class... Args> | |
| jthread_alias (F &&f, Args &&... args) | |
Start a new thread by forwarding arguments to the underlying std::thread. | |
| jthread_alias (jthread_alias &&) noexcept=default | |
| jthread_alias & | operator= (jthread_alias &&) noexcept=default |
| jthread_alias (const jthread_alias &)=delete | |
| jthread_alias & | operator= (const jthread_alias &)=delete |
| ~jthread_alias () | |
| Join the underlying thread on destruction if still joinable. | |
| bool | joinable () const noexcept |
| Check whether the underlying thread can be joined. | |
| void | join () |
| Join the underlying thread. | |
| void | detach () |
| Detach the underlying thread. | |
| std::thread::id | get_id () const noexcept |
| Get the underlying thread id. | |
| auto | native_handle () |
| Access the native handle of the underlying thread. | |
| void | swap (jthread_alias &other) noexcept |
| Swap the underlying thread with another wrapper. | |
This class is used when std::jthread is not available in the standard library.
Ownership model:
std::thread instance.Differences vs std::jthread:
Typical usage:
Definition at line 72 of file gthreads.h.
|
defaultnoexcept |
After default construction, joinable() returns false.
|
inlineexplicit |
| F | Callable type. |
| Args | Argument pack forwarded to f. |
| f | Callable to run in the new thread. |
| args | Arguments passed to f. |
explicit to avoid accidental implicit thread starts. Definition at line 101 of file gthreads.h.
|
defaultnoexcept |
|
delete |
|
inline |
This mirrors the "safe by default" behavior typically sought with std::jthread.
Definition at line 118 of file gthreads.h.
|
inline |
After detaching, the wrapper no longer represents a joinable thread, and the destructor will not join.
Definition at line 142 of file gthreads.h.
|
inlinenoexcept |
std::thread::id of the owned thread. Definition at line 148 of file gthreads.h.
|
inline |
Preconditions match std::thread::join.
std::thread rules (typically terminating the program). Definition at line 134 of file gthreads.h.
|
inlinenoexcept |
true if joinable, false otherwise. Definition at line 124 of file gthreads.h.
|
inline |
std::thread::native_handle.Definition at line 156 of file gthreads.h.
|
delete |
|
defaultnoexcept |
|
inlinenoexcept |
| other | Wrapper to swap with. |
After swapping, each wrapper owns the other's prior thread.
Definition at line 164 of file gthreads.h.