Get the App
SLTechnology News&Howtos  ›  Development  › 

How to understand the thread and lock and condition variables in Clover 11

Shulou Source: shulou.com Published: 2022-06-02 20:31:34 09月26日 Update

Today, I would like to talk to you about how to understand the threads and locks and condition variables in Clover 11. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something from this article.

Thread

The class std::thread represents an executable thread and must include a header file when used. Std::thread can be used with ordinary functions, anonymous functions, and mock functions (a class that implements the operator () function). In addition, it allows any number of arguments to be passed to the thread function.

# include void func () {/ / do some work} int main () {std::thread t (func); t.join (); return 0;}

In the above example, t is a thread object in which the function func () runs. The call to the join () function keeps the calling thread (in this case, the main thread) blocking until the t execution of the executing thread ends. If a thread function returns a value, the value is also ignored. However, this function can accept any number of parameters.

Void func (int I, double d, const std::string& s) {std::cout

Tags: Threads functions methods conditions variables containers states blocking two signals parameters false results encapsulation examples errors facets synchronization output run Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux OPPO Reno Shulou Technology MySQL Xiaomi