vtk/QT 環境で c++ でプログラムを書いています。ただし、この問題は主にアプローチ/アルゴリズムの問題です。
実行中の 3 つのスレッドを同期しようとして行き詰まりました。スレッド: 「出力」バッファと「入力」バッファからデータを取得し、レンダリングのために別々のプロット バッファに追加します。
これらのスレッドを同期して実行したいので、スレッドごとに 1 つの条件変数をブール条件と一緒に使用するアプローチを試しました。上記の順序。ただし、これを行うとデッドロックが発生し、プログラムが停止します。ここでいくつかの入力をいただければ幸いです:)
コードでの私のアプローチは次のとおりです。
//ブール変数の初期条件:
readyForTransmit=true;
readyForReceive=false;
readyForPlotting=false;
スレッド 1 - 送信:
while(1){
mutex->Lock();
//waits for condition/signal to proceed
while(!readyForTransmit)
transmitConditionVariable->wait(mutex);
readyForTransmit=false;
mutex->Unlock();
//Here I transmit my sample
transmit();
//Triggers next thread - reception
mutex->Lock();
readyForReceive=true;
receiveConditionVariable->broadcast(); //Have also tried signal();
mutex->Unlock();
}
スレッド 2 - 受信:
while(1){
mutex->Lock();
//waits for condition/signal to proceed
while(!readyForReceive)
receiveConditionVariable->wait(mutex);
readyForReceive=false;
mutex->Unlock();
//Here I receive my sample
receive();
//Triggers next thread - reception
mutex->Lock();
readyForPlotting=true;
plottingConditionVariable->broadcast(); //Have also tried signal();
mutex->Unlock();
}
スレッド 3 - プロット バッファーに追加します。
while(1){
mutex->Lock();
//waits for condition/signal to proceed
while(!readyForPlotting)
plottingConditionVariable->wait(mutex);
readyForPlotting=false;
mutex->Unlock();
//Here I adds samples to plotting buffer
updatePlottingBuffers();
//Triggers next thread - reception
mutex->Lock();
readyForTransmit=true;
transmitConditionVariable->broadcast(); //Have also tried signal();
mutex->Unlock();
}
これに加えて、スレッドセーフなサンプルをバッファーとの間でプッシュおよびプルします。だから、それは問題ではないはずです。
返事を待っております!=)