This code does not work:

cond_var[myID].wait(unique_lock<mutex>(mtx[myID])); 

The variable declaration is:

 condition_variable cond_var[32]; mutex mtx[32]; 

What does MVS say: enter image description here

    1 answer 1

    First, std::condition_variable::wait_for either two or three parameters .

    Secondly, the first parameter std::condition_variable::wait_for is an lvalue-link. It cannot be tied to a temporary object.

    This is what the compiler tells you.

    What did you want to say, passing one argument there?

    • So that the program does not eat CPU resources, until the next thread finishes its work - Alleksh _
    • I saw this code on the Internet. In the video, he worked, the processor is not loaded. - Alleksh _
    • @Alleksh_ I can still believe in the transfer of a temporary object by reference — the MSVC extension, but the fact that the two-parameter function was compiled with one argument is not. You are confusing something. - AnT
    • timecode 4:16 youtube.com/… - Alleksh _
    • @Alleksh_, there is no wait_for - Abyx