2 // Copyright Oliver Kowalke 2013.
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
11 #include <condition_variable>
14 #include <boost/assert.hpp>
22 std::condition_variable cond_{};
25 explicit barrier( std::size_t initial) :
27 current_{ initial_ } {
28 BOOST_ASSERT ( 0 != initial);
31 barrier( barrier const&) = delete;
32 barrier & operator=( barrier const&) = delete;
35 std::unique_lock< std::mutex > lk( mtx_);
36 const bool cycle = cycle_;
37 if ( 0 == --current_) {
40 lk.unlock(); // no pessimization
44 cond_.wait( lk, [&](){ return cycle != cycle_; });