thread Class members

The following table provides additional information on the members of this template class.
Member Description
thread()

Constructs a thread that does not represent a thread of execution, with get_id()==id().

template<typename F> thread(F f)

Construct a thread that evaluates f()

template<typename F, typename X> thread(F f, X x)

Constructs a thread that evaluates f(x).

template<typename F, typename X, typename Y> thread(F f, X x, Y y)

Constructs thread that evaluates f(x,y).

thread(thread&& x)

Constructs *this to have the state of x and sets x to default-constructed state.

thread& operator=(thread&& x)

If joinable(), calls detach(). Then assigns the state of x to *this and sets x to default-constructed state.

thread& operator=(thread& x)

If joinable(), calls detach(). Then assigns the state of x to *this and sets x to default-constructed state.

CAUTION

It's a limited emulation of a C++11 move assignment. Not provided for C++11 and beyond.

~thread

if( joinable() ) detach().

void swap(thread& x)

Effects: Swaps *this and x.

bool joinable() const

Returns: get_id()!=id()

void join()

Requirements: joinable()==true

Effects: Wait for thread to complete. Afterwards, joinable()==false.

void detach()

Requirements: joinable()==true

Effects: Sets *this to default-constructed state and returns without blocking. The thread represented by *this continues execution.

id get_id() const

Returns: id of the thread, or a default-constructed id if *this does not represent a thread.

native_handle_type native_handle()

Returns: Native thread handle. The handle is a HANDLE on Windows* operating systems and a pthread_t on Linux* and macOS* operating systems. For these systems, native_handle() returns 0 if joinable()==false.

static unsigned hardware_concurrency()

Returns: The number of hardware threads. For example, 8 on a system with an Intel® Core™ i7-6700K Processor with 4 cores and 8 hardware threads.

For more complete information about compiler optimizations, see our Optimization Notice.