Get the App
SLTechnology News&Howtos  ›  Development  › 

How to comprehend the std::thread in Category 11

Shulou Source: shulou.com Published: 2022-06-03 05:04:46 10月03日 Update

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

Tags: Functions objects threads copies questions examples files more help answers easy successful easy representatives content parameters boys buddies means members Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Redmi macOS Xiaomi Shulou Technology