私は私のスレッドで、次のコードで、NUM_THREADSスレッドを持っている:ブースト同期
/*
Calculate some_value;
*/
//Critical section to accummulate all thresholds
{
boost::mutex::scoped_lock lock(write_mutex);
T += some_value;
num_threads++;
if (num_threads == NUM_THREADS){
T = T/NUM_THREADS;
READY = true;
cond.notify_all();
num_threads = 0;
}
}
//Wait for average threshold to be ready
if (!READY)
{
boost::unique_lock<boost::mutex> lock(wait_mutex);
while (!READY){
cond.wait(lock);
}
}
//End critical section
/*
do_something;
*/
基本的に、私は、すべてのスレッドが継続する前に、READY信号を待ちたいです。 num_threadは0に設定され、READYはスレッドが作成される前にfalseになります。一度、デッドロックが発生します。誰でも助けてくれますか?次のように すべてのブースト変数がグローバルに宣言されています
boost::mutex write_mutex;
boost::mutex wait_mutex;
boost::condition cond;
バックは 'false'に' READY'を設定しますか?それとも、デッドロックが発生していて、うまく動作している実行中であることを意味しますか? –
READYは、すべてのスレッドが終了するとfalseに設定されます。はい、ほとんどの場合、デッドロックを除いて正常に動作します。ありがとう! – Mickey