だから、単純なクラスブーストミューテックス順
class mySafeData
{
public:
mySafeData() : myData(0)
{
}
void Set(int i)
{
boost::mutex::scoped_lock lock(myMutex);
myData = i; // set the data
++stateCounter; // some int to track state chages
myCondvar.notify_all(); // notify all readers
}
void Get(int& i)
{
boost::mutex::scoped_lock lock(myMutex);
// copy the current state
int cState = stateCounter;
// waits for a notification and change of state
while (stateCounter == cState)
myCondvar.wait(lock);
}
private:
int myData;
int stateCounter;
boost::mutex myMutex;
};
と
Get()
Set()
Get()
Get()
Get()
彼らは常に円ごとに一度だけ同じ順序で関数を呼び出すとなり、それぞれの機能を呼び出す無限ループ内のスレッドの配列を(持ちますサークルでは、すべてのスレッドが毎回同じ順番で実行されることを意味するので、各スレッドは()の後に1回だけGet
()となるでしょうか?