cpp/thread/jthread

The class represents a single thread of execution. It has the same general behavior as std, except that automatically rejoins on destruction, and can be cancelled/stopped in certain situations.

Threads begin execution immediately upon construction of the associated thread object (pending any OS scheduling delays), starting at the top-level function provided as a. The return value of the top-level function is ignored and if it terminates by throwing an exception, std is called. The top-level function may communicate its return value or an exception to the caller via std or by modifying shared variables (which may require synchronization, see std and std).

Unlike std, the logically holds an internal private member of type, which maintains a shared stop-state. The constructor accepts a function that takes a std as its first argument, which will be passed in by the  from its internal std. This allows the function to check if stop has been requested during its execution, and return if it has.

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 objects (after detach).

No two objects may represent the same thread of execution;  is not  or, although it is  and.