- The C Standard Library
- The C Standard Library
- The C++ Standard Library
- C++ Library - Home
- C++ Library - <fstream>
- C++ Library - <iomanip>
- C++ Library - <ios>
- C++ Library - <iosfwd>
- C++ Library - <iostream>
- C++ Library - <istream>
- C++ Library - <ostream>
- C++ Library - <sstream>
- C++ Library - <streambuf>
- C++ Library - <atomic>
- C++ Library - <complex>
- C++ Library - <exception>
- C++ Library - <functional>
- C++ Library - <limits>
- C++ Library - <locale>
- C++ Library - <memory>
- C++ Library - <new>
- C++ Library - <numeric>
- C++ Library - <regex>
- C++ Library - <stdexcept>
- C++ Library - <string>
- C++ Library - <thread>
- C++ Library - <tuple>
- C++ Library - <typeinfo>
- C++ Library - <utility>
- C++ Library - <valarray>
- The C++ STL Library
- C++ Library - <array>
- C++ Library - <bitset>
- C++ Library - <deque>
- C++ Library - <forward_list>
- C++ Library - <list>
- C++ Library - <map>
- C++ Library - <queue>
- C++ Library - <set>
- C++ Library - <stack>
- C++ Library - <unordered_map>
- C++ Library - <unordered_set>
- C++ Library - <vector>
- C++ Library - <algorithm>
- C++ Library - <iterator>
- C++ Programming Resources
- C++ Programming Tutorial
- C++ Useful Resources
- C++ Discussion
C++ Atomic Library - load
Description
It atomically obtains the value of the atomic object.
Declaration
Following is the declaration for std::atomic::load.
T load( std::memory_order order = std::memory_order_seq_cst ) const;
C++11
T load( std::memory_order order = std::memory_order_seq_cst ) const volatile;
Parameters
order − It is used to enforce memory order constraints.
Return Value
It returns the current value of the atomic variable.
Exceptions
No-noexcept − this member function never throws exceptions.
Example
In below example for std::atomic::load.
#include <atomic> #include <thread> std::atomic<int> foo (0); void set_foo(int x) { foo.store(x,std::memory_order_relaxed); } void print_foo() { int x; do { x = foo.load(std::memory_order_relaxed); } while (x==0); std::cout << "test: " << x << '\n'; } int main () { std::thread first (print_foo); std::thread second (set_foo,10); first.join(); second.join(); return 0; }
atomic.htm
Advertisements