Hello, please tell me how to make the 1st and 2nd functions run simultaneously, and wait for the third while both of them are executed? Thank you in advance. Here is the code, but on the third
#include "stdafx.h" #include <Windows.h> #include <iostream> #include <stdio.h> #include <thread> #include <string> #include <vector> #include <mutex> #include <future> #include <conio.h> using namespace std; mutex g_lock; mutex c_lock; void anyFunc1(mutex& mtx) { mtx.lock(); for (int i = 0; i < 10; i++) { Sleep(400); cout << "1 \n"; } } void anyFunc2(mutex& mtx) { for (int i = 0; i < 10; i++) { Sleep(400); cout << "2 \n"; } mtx.unlock(); } void anyFunc3(mutex& mtx) { mtx.lock(); for (int i = 0; i < 10; i++) { Sleep(400); cout << "3 \n"; } mtx.unlock(); } int main() { mutex mtx; setlocale(LC_ALL, "rus"); thread func_thread1(anyFunc1, ref(mtx)); thread func_thread2(anyFunc2, ref(mtx)); thread func_thread3(anyFunc3, ref(mtx)); func_thread1.join(); func_thread2.join(); func_thread3.join(); system("pause"); return 0; }