3 class spinning_barrier {
5 spinning_barrier (unsigned int n) : n_ (n), nwait_ (0), step_(0) {}
8 unsigned int step = step_.load ();
10 if (nwait_.fetch_add (1) == n_ - 1) {
11 /* OK, last thread to come. */
12 nwait_.store (0); // XXX: maybe can use relaxed ordering here ??
16 /* Run in circles and scream like a little girl. */
17 while (step_.load () == step)
24 /* Number of synchronized threads. */
25 const unsigned int n_;
27 /* Number of threads currently spinning. */
28 std::atomic<unsigned int> nwait_;
30 /* Number of barrier syncronizations completed so far,
31 * * it's OK to wrap. */
32 std::atomic<unsigned int> step_;