Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Multithreading 我不理解分离线程上的C++11条件_变量的细节_Multithreading_C++11_Condition Variable - Fatal编程技术网

Multithreading 我不理解分离线程上的C++11条件_变量的细节

Multithreading 我不理解分离线程上的C++11条件_变量的细节,multithreading,c++11,condition-variable,Multithreading,C++11,Condition Variable,我在分离的线程中运行了两段代码: { std::lock_guard<std::mutex> lck( interThreadLockMtx ); //std::unique_lock<std::mutex> lckGiveCond( mtxCondVar ); condVarGivePasswd.notify_one(); std::unique_lock<std::mutex> lckCond( condVarTake

我在分离的线程中运行了两段代码:

{
    std::lock_guard<std::mutex> lck( interThreadLockMtx );

    //std::unique_lock<std::mutex> lckGiveCond( mtxCondVar );

    condVarGivePasswd.notify_one();

    std::unique_lock<std::mutex> lckCond( condVarTakePasswdMtx );
    condVarTakePasswd.wait( lckCond );

    passwd = newPasswd;
}

似乎我这里的竞争条件是std::unique_lock,这对于等待调用是必需的。

似乎我这里的竞争条件是std::unique_lock,这对于等待调用是必需的。我只是删除了所有条件变量,让控制线程什么也不做。相反,工作线程自己完成工作,而不向控制线程请求信息

    for (;;)
    {
        std::unique_lock<decltype(mtxCondVar)> mtxCondVarLock( mtxCondVar );
        condVarGivePasswd.wait( mtxCondVarLock );
        newPasswd = genNewPasswd();
        //std::unique_lock<std::mutex> lckCond( condVarTakePasswdMtx );
        condVarTakePasswd.notify_one();
    }
Process 63102 stopped
* thread #1: tid = 0x142f17, 0x00007fff86fba716 libsystem_kernel.dylib`__psynch_cvwait + 10,     queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
thread #2: tid = 0x142f31, 0x00007fff86fba716 libsystem_kernel.dylib`__psynch_cvwait + 10
thread #3: tid = 0x142f32, 0x00007fff86fba746 libsystem_kernel.dylib`__psynch_mutexwait + 10
thread #4: tid = 0x142f33, 0x00007fff86fba746 libsystem_kernel.dylib`__psynch_mutexwait + 10
thread #5: tid = 0x142f34, 0x00007fff86fba746 libsystem_kernel.dylib`__psynch_mutexwait + 10