Re: [Boost-bugs] [Boost C++ Libraries] #4725: Synchronisation and shared mutex's Get total_count

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #4725: Synchronisation and shared mutex's Get total_count
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-11-27 18:13:14


#4725: Synchronisation and shared mutex's Get total_count
------------------------------------------+---------------------------------
  Reporter: dominicstreeter@… | Owner: anthonyw
      Type: Feature Requests | Status: new
 Milestone: To Be Determined | Component: thread
   Version: Boost 1.44.0 | Severity: Problem
Resolution: | Keywords: Synchronisation Barriers Get total_count
------------------------------------------+---------------------------------

Comment (by dominicstreeter@…):

 I wish to close this ticket on the grounds that the above code is flawed
 and a work around the problem faced here requires a seperate class to
 encapsulate a count of the total threads being used. Although there is no
 method for getting the total threads locked in a barrier from the class
 you can encapsulate this functionality in your own class outside of a
 barrier class and pass in the expected total threads to be waiting from
 there.

 To explain what the barrier class that encapsulates/replaces this
 mechanism actually ended up looking like here is a rough abstract of my
 working barrier.

         boost::mutex mutAccessData;

         boost::condition_variable_any multiThreadLink;

         int intThreadsCaughtCount;

 You pass in the number of threads registered to be waiting with the scene
 if they are all waiting on the barrier you wake them up and return true
 signalling success to a managing thread that might be waiting for all of
 them to be at the barrier.
         bool getWakeUpIfAllReady(int intThreadsHandledByObject)
         {
                         bool boolIsAwoken;

                         mutAccessData.lock();

                         if (intThreadsCaughtCount ==
 intThreadsHandledByObject)
                         {
                                 multiThreadLink.notify_all();

                                 boolIsAwoken = true;
                         }
                         else
                         {
                                 boolIsAwoken = false;
                         }

                         mutAccessData.unlock();

                         return boolIsAwoken;
         }

 This is called by threads that need to wait until they are woken up.
         void waitUntilAllReady()
         {
                         mutAccessData.lock();

                         intThreadsCaughtCount++;

                         multiThreadLink.wait(mutAccessData);

                         intThreadsCaughtCount--;

                         mutAccessData.unlock();
         }

 There were one or two scenarios where the rewritten get total threads
 might be useful for handling complex state logic for a shutdown during an
 erroneous event; however even that use has alternate work arounds which I
 have used now. Therefore I wish to retract my ticket.

 Perhaps a boost class to encapsulate this behaviour might be of value? If
 not this would be a useful exercise to do for an example in the boost
 documentation on threading for newcomers. Anyway thank you for your time
 :)

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/4725#comment:3>
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