How to comprehend the std::thread in Category 11
This article introduces in detail the corresponding analysis and solution to how to understand the std::thread in Cellular 11, hoping to help more partners who want to solve this problem to find a more simple and feasible way.
Std::thread is declared in the header file, so you need to include the header file when using std::thread.
Std::thread construction
Thread () noexcept
Template explicit thread (Fn&& fn, Args&&... Args)
Thread (const thread&) = delete
Thread (thread&& x) noexcept
Default (1) initialization (2) copy [deleted] (3) move (4)
(1)。 Default constructor to create an empty thread execution object. (2)。 Initialize the constructor and create a thread object that can be joinable, and the newly generated thread calls the fn function, whose parameters are given by args. (3)。 Copy constructor (disabled), which means that thread cannot be copied and constructed. (4)。 Move constructor, move constructor, x does not represent any thread execution object after a successful call.
Note: thread objects that can be joinable must be join or set to detached by the main thread before they are destroyed.
Examples of various constructors for std::thread are as follows (see):
# include # include void F1 (int n) {for (int I = 0; I < 5; + + I) {std::cout