How to apply thread locks and condition variables in Category 11
This article mainly introduces the relevant knowledge of how to apply thread locks and condition variables in Craft 11, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe that you will gain something after reading this article on how to apply thread locks and condition variables. Let's take a look.
Thread
The std::thread class, located in the header file, implements threading operations. Std::thread can be used with normal functions and lambda expressions. It also allows you to pass any number of parameters to the thread's execution 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 instance in which the function func () runs. The join () function is called to block the current thread (in this case, the main thread) until the t thread finishes executing. The return value of the thread function is ignored, but the thread function accepts any number of input parameters.
Void func (int I, double d, const std::string& s) {std::cout