The class Thread
can represent a single thread of execution. Threads allow multiple functions to execute concurrently.
Threads may begin execution immediately upon construction of the associated thread object (pending any OS scheduling delays), starting at the top-level function provided as a constructor argument. The return value of the top-level function is ignored. The top-level function may communicate its return value by modifying shared variables (which may require synchronization, see pw_sync
and std::atomic
)
Thread
objects may also be in the state that does not represent any thread (after default construction, move from, detach, or join), and a thread of execution may be not associated with any thread objects (after detach).
No two Thread
objects may represent the same thread of execution; Thread
is not CopyConstructible or CopyAssignable, although it is MoveConstructible and MoveAssignable.
Public Types | |
using | native_handle_type = backend::NativeThreadHandle |
using | id = ::pw::thread::backend::NativeId |
Public Member Functions | |
Thread () | |
Thread (const Options &options, Function< void()> &&entry) | |
template<const ThreadAttrs & kAttributes> | |
Thread (ThreadContextFor< kAttributes > &context, Function< void()> &&entry) | |
template<size_t kStackSizeHintBytes> | |
Thread (ThreadContext< kStackSizeHintBytes > &context, const ThreadAttrs &attributes, Function< void()> &&entry) | |
Thread (ThreadContext<> &context, const ThreadAttrs &attributes, Function< void()> &&entry) | |
Thread & | operator= (Thread &&other) |
~Thread () | |
Thread (const Thread &)=delete | |
Thread (Thread &&)=delete | |
Thread & | operator= (const Thread &)=delete |
id | get_id () const |
bool | joinable () const |
template<typename... , bool kJoiningEnabled = false> | |
void | join () |
void | detach () |
void | swap (Thread &other) |
Exchanges the underlying handles of two thread objects. | |
native_handle_type | native_handle () |