c++ - how to use boost barrier -


What is the boost: hurdle, how to use this type of boost method Can you give me a clear example because I Examples were found at the following:

  bool wait () {boost :: mutex :: scoped_lock lock (m_mutex); Unsigned int gen = m_generation; If (--m_count == 0) {m_generation ++; M_count = m_thholdhold; M_cond.notify_all (); Back true; } While (Jean == m_generation) m_cond.wait (lock); return false; }   

In the above code: m_cond.notify_all (); Want to enter other waiting threads? Can you tell me clearly about the functionality of the obstacle? Thank you.

Notify- wait for the notified thread.

An obstacle is a simple concept, it is also known as a meeting place, it is a synchronization point between multiple threads. The handicap is configured for a specific number of threads (N), and they will have to wait until the threads arrive to reach the barrier of the thread. Once threshold threads reach the barrier, all waiting threads can proceed, and the hurdle is reset.

Simple example The current value will be output only when wait for the function on thread thread 3.

  #include & lt; Boost / thread.hpp & gt; #include & lt; Boost / thread / barrier.hpp & gt; # Include & lt; Boost / bind.hpp & gt; #include & lt; Boost / atomic.hpp & gt; Boost: Mute x io_mutex; Void thread_fun (boost :: constraint & cur_barier, boost :: atomic & lt; int & gt; and current) {++; Present; Cur_barier.wait (); Promote: lock_guard & lt; Promotion :: Muttex & gt; Locker (io_mutex); Std :: cout & lt; & Lt; Current & lt; & Lt; Std :: endl; } Int main () {boost :: barrier bar (3); Promote: Atomic & LT; Int & gt; Current (0); Promotion: Thread thr1 (boost :: tie (and thread_fun, boost :: ref (bar), boost :: ref (current)); Promotion: thread thr2 (boost :: bind (and thread_fun, boost: ref (bar), boost :: ref (current)); Promotion: thread thr3 (boost :: bind (and thread_fun, boost :: ref (bar), boost :: ref (current)); Thr1.join (); Thr2.join (); Thr3.join (); }    

Comments