Subject: [Boost-bugs] [Boost C++ Libraries] #4725: Synchronisation and shared mutex's Get total_count
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-10-10 14:48:30
#4725: Synchronisation and shared mutex's Get total_count
------------------------------------------------------+---------------------
Reporter: dominicstreeter@⦠| Owner: anthonyw
Type: Feature Requests | Status: new
Milestone: To Be Determined | Component: threads
Version: Boost 1.44.0 | Severity: Problem
Keywords: Synchronisation Barriers Get total_count |
------------------------------------------------------+---------------------
Hey there I wish to create what is in essence a barrier but with the
capacity to flexibly dictate how many threads are in the barrier. The
problem is synchronising.
Here is an example of the problem that shows I need to get the total count
of threads accessing the shared total_count variable atomically from the
boost library. I would like to know if there is a reason this is not
implemented.
Here are some variables to demonstrate the issue.
boost::condition_variable_any multiThreadLinkReady;
boost::shared_mutex smutDependancyThreadCustomBarrierReady;
bool boolIsSceneReady;
//Run by a management thread
void wakeUpIfAllReady()
{
mutAccessData.lock();
if (intThreadsCaughtCountPost >= TOTALTHREADSLOADINGSCENE)
{
if (Here I need to the total count to also equal the Constant
TOTALTHREADSLOADINGSCENE to garuntee every thread wakes up in a one time
call to notify all of them into the next stage)
multiThreadLinkReady.notify_all();
boolIsSceneReady = true;
}
mutAccessData.unlock();
}
//Run by every thread but the management thread relating to this data
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. It possible for this to not be set before the other
thread calls notify all!
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
{
mutAccessData.unlock();
}
}
There is no way of avoiding using interrupts when using the available
barrier mechanism with a complex system involving alot of states this is
not always desirable. If a thread were to fail and you needed to bail the
other threads out of the barrier class you need to do alot more than if
you can use a conditional variable like this and get the total threads
that are actively waiting, creating a flexible barrier.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/4725> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:04 UTC