Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/atomic/atomic flag"

From cppreference.com
< cpp‎ | atomic
m (+memory orders (saves one mfence out of three emitted by my gcc))
(fmt)
Line 26: Line 26:
 
#include <iostream>
 
#include <iostream>
 
#include <atomic>
 
#include <atomic>
 +
 
std::atomic_flag lock = ATOMIC_FLAG_INIT;
 
std::atomic_flag lock = ATOMIC_FLAG_INIT;
 +
 
void f(int n)
 
void f(int n)
 
{
 
{
Line 39: Line 41:
 
{
 
{
 
     std::vector<std::thread> v;
 
     std::vector<std::thread> v;
     for(int n=0; n<10; ++n)
+
     for (int n = 0; n < 10; ++n) {
 
         v.emplace_back(f, n);
 
         v.emplace_back(f, n);
     for(auto& t : v)
+
    }
 +
     for (auto& t : v) {
 
         t.join();
 
         t.join();
 +
    }
 
}
 
}
 
  | output=
 
  | output=

Revision as of 08:20, 15 October 2011

Template:cpp/atomic/atomic flag/sidebar Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <atomic>
</td>

<td></td> <td></td> </tr> <tr class="t-dcl ">

<td >
class atomic_flag;
</td>

<td class="t-dcl-nopad"> </td> <td > Template:mark c++11 feature </td> </tr> Template:ddcl list end

An Template:cpp is an atomic boolean type. Unlike all specializations of Template:cpp, it is guaranteed to be lock-free.

Member functions

Template:cpp/atomic/atomic flag/dcl list clearTemplate:cpp/atomic/atomic flag/dcl list test and set
constructs an atomic_flag
(public member function)
the assignment operator
(public member function)

Example

Template:example cpp

See also

Template:cpp/atomic/dcl list atomic flag test and setTemplate:cpp/atomic/dcl list atomic flag clearTemplate:cpp/atomic/dcl list ATOMIC FLAG INIT