Delen via


thread Class

Defines an object that's used to observe and manage a thread of execution within an application.

class thread;

Remarks

You can use a thread object to observe and manage a thread of execution within an application. A thread object that's created by using the default constructor is not associated with any thread of execution. A thread object that's constructed by using a callable object creates a new thread of execution and calls the callable object in that thread. Thread objects can be moved but not copied. Therefore, a thread of execution can be associated with only one thread object.

Every thread of execution has a unique identifier of type thread::id. The function this_thread::get_id returns the identifier of the calling thread. The member function thread::get_id returns the identifier of the thread that's managed by a thread object. For a default-constructed thread object, the thread::get_id method returns an object that has a value that's the same for all default-constructed thread objects and different from the value that's returned by this_thread::get_id for any thread of execution that could be joined at the time of the call.

Members

Public Classes

Name

Description

thread::id Class

Uniquely identifies the associated thread.

Public Constructors

Name

Description

thread::thread Constructor

Constructs a thread object.

Public Methods

Name

Description

thread::detach Method

Detaches the associated thread from the thread object.

thread::get_id Method

Returns the unique identifier of the associated thread.

thread::hardware_concurrency Method

Static. Returns an estimate of the number of hardware thread contexts.

thread::join Method

Blocks until the associated thread completes.

thread::joinable Method

Specifies whether the associated thread is joinable.

thread::native_handle Method

Returns the implementation-specific type that represents the thread handle.

thread::swap Method

Swaps the object state with a specified thread object.

Public Operators

Name

Description

thread::operator= Operator

Associates a thread with the current thread object.

Requirements

Header: thread

Namespace: std

See Also

Reference

<thread>

Other Resources

C++ Standard Library Header Files