You can skip to the end line for a rundown of what I need or read the fine print here.
I need an atmoc way to see the number of threads that are waiting inside a shared mutex.
These are the variables I use.
boost::condition_variable_any multiThreadLinkReady;
boost::shared_mutex smutDependancyThreadCustomBarrierReady;
bool boolIsSceneReady;
This is the code I run to wait until they are all ready, I cannot lock with the wait value set, so I need to atomically check this in the other function to garuntee every thread gets awoken when every thread is gathered.
void waitUntilAllReady() { mutAccessData.lock(); if (boolIsSceneReady == false) { intThreadsCaughtCountPost++; mutAccessData.unlock(); //The thread is set to frozen to be awoken on the next line when the class is ready. multiThreadLinkReady.wait(smutDependancyThreadCustomBarrierReady); //So we can reuse this on the next level loaded we need to decrement the counter. mutAccessData.lock(); intThreadsCaughtCountPost--; mutAccessData.unlock(); } else { //Not impossible to reach here but very unlikely depends on lots of thread lag. mutAccessData.unlock(); } }
Then there is this threaded function which only one thread uses to manage the other threads, I need another if to check that the smutDependancyThreadCustomBarrierReady has the TOTALTHREADSLOADINGSCENE attached to it before allowing notify to be called or my threads never wake up!
void wakeUpIfAllReady() { mutAccessData.lock(); if (intThreadsCaughtCountPost >= TOTALTHREADSLOADINGSCENE) { multiThreadLinkReady.notify_all(); boolIsSceneReady = true; } mutAccessData.unlock(); }
Does anyone know of a method in boost to perform the function in the title?