[Boost-bugs] [Boost C++ Libraries] #12120: Performance improvement in thread/barrier.hpp

Subject: [Boost-bugs] [Boost C++ Libraries] #12120: Performance improvement in thread/barrier.hpp
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-04-11 19:50:03

#12120: Performance improvement in thread/barrier.hpp
 Reporter: Ronald Holthuizen <ronald@…> | Owner: anthonyw
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: thread
  Version: Boost 1.61.0 | Severity: Optimization
 Keywords: barrier wait performance |
 The current Boost code in thread/barrier.hpp has this code:

     bool wait()
       boost::unique_lock < boost::mutex > lock(m_mutex);
       unsigned int gen = m_generation;

       if (--m_count == 0)
         m_count = static_cast<unsigned int>(fct_());
         BOOST_ASSERT(m_count != 0);
         return true;

       while (gen == m_generation)
       return false;
 In the line m_cond.notify_all(); m_mutex is locked while the other threads
 are notified. This is a performance anti-pattern: the notified threads
 will first have to wait for the mutex to be released.

 By adding the line:
 before the m_cond.notify_all(); the performance of the barrier class is

 More info why this is better, see sample in:

Ticket URL: <https://svn.boost.org/trac/boost/ticket/12120>
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:20 UTC