id,summary,reporter,owner,description,type,status,milestone,component,version,severity,resolution,keywords,cc 12120,Performance improvement in thread/barrier.hpp,Ronald Holthuizen ,viboes,"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_generation++; m_count = static_cast(fct_()); BOOST_ASSERT(m_count != 0); m_cond.notify_all(); return true; } while (gen == m_generation) m_cond.wait(lock); 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: lock.unlock(); before the m_cond.notify_all(); the performance of the barrier class is improved. More info why this is better, see sample in: http://en.cppreference.com/w/cpp/thread/condition_variable ",Bugs,closed,Boost 1.62.0,thread,Boost 1.61.0,Optimization,fixed,barrier wait performance,