Move semantics and Rvalue Reference (from C++11 Thread tutorial) Rvalue and Lvalue (from C++11 Thread tutorial) Static assertions and Constructor delegation The nullptr and strongly typed enumerations Type Inference (auto) and Range-based for loop By just putting the i as in the following line, we can pass the index into the thread function: Since we're using lambda, we can utilize its capture capability. Non-deterministic nature of concurrent programmingĪs we can see from the output, we cannot tell which thread is printing which. Then, joins one by one, and this works like barrier. The lambda function takes its argument as a reference to a thread, t. The '' tells the compiler we're using lambda. ![]() We loop through every thread via for_each(), and its 3rd argument assigns a task. The vector container workers stores 5 threads created, and after they finished the task they are joined with the main thread: Std::for_each(workers.begin(), workers.end(), (std::thread &t) ![]() Then, joins one by one, and this works like barrier The lambda function takes its argument as a reference to a thread, t It tells the compiler we're using lambda () In this section, we'll see the usefulness of lambda function for multi-threading.
0 Comments
Leave a Reply. |