命名空间
变体
操作

标准库头文件 <hazard_pointer> (C++26)

来自 cppreference.cn
< cpp‎ | header
 
 
标准库头文件
算法
<algorithm>
<numeric>
字符串
<cctype>
<cstring>
<cuchar> (C++11)
<cwchar>
<cwctype>
<string_view> (C++17)
<string>
文本处理
<clocale>
<codecvt> (C++11/17/26* 已弃用,在 C++26 中移除)
<locale>
<regex> (C++11)
<text_encoding> (C++26)   
数值
<cfenv> (C++11)
<cmath>
<complex>
<linalg> (C++26)
<numbers> (C++20)
<random> (C++11)
<simd> (C++26)
<valarray>
时间
<chrono> (C++11)
<ctime>
C 兼容性
<ccomplex> (C++11/17/20* 已弃用,在 C++20 中移除)
<ciso646> (直到 C++20)
<cstdalign> (C++11/17/20* 已弃用,在 C++20 中移除)
<cstdbool> (C++11/17/20* 已弃用,在 C++20 中移除)
<ctgmath> (C++11/17/20* 已弃用,在 C++20 中移除)
输入/输出
<cinttypes> (C++11)
<cstdio>
<filesystem> (C++17)
<fstream>
<iomanip>
<iosfwd>
<iostream>
<ios>
<istream>
<ostream>
<print> (C++23)
<spanstream> (C++23)
<sstream>
<streambuf>
<strstream> (C++98/26* 已弃用,在 C++26 中移除)
<syncstream> (C++20)
并发支持
<atomic> (C++11)
<barrier> (C++20)
<condition_variable> (C++11)
<future> (C++11)
<hazard_pointer> (C++26)
<latch> (C++20)
<mutex> (C++11)
<rcu> (C++26)
<semaphore> (C++20)
<shared_mutex> (C++14)
<stdatomic.h> (C++23)
<stop_token> (C++20)
<thread> (C++11)
执行支持
<execution> (C++17)



 

此头文件是线程支持库的一部分。

内容

允许对象可进行危害保护
(类模板) [编辑]
单写多读指针,在任何时间点最多只能由一个线程拥有
(类) [编辑]

函数

构造危害指针
(函数) [编辑]
特化了 std::swap 算法
(函数模板) [编辑]

[编辑] 概要

namespace std {
  // hazard_pointer_obj_base
  template<class T, class D = default_delete<T>> class hazard_pointer_obj_base;
 
  // hazard_pointer
  class hazard_pointer;
 
  // make_hazard_pointer
  hazard_pointer make_hazard_pointer();
  void swap(hazard_pointer&, hazard_pointer&) noexcept;
}

[编辑] 类模板 std::hazard_pointer_obj_base

namespace std {
  template<class T, class D = default_delete<T>>
  class hazard_pointer_obj_base {
  public:
    void retire(D d = D()) noexcept;
  protected:
    hazard_pointer_obj_base() = default;
    hazard_pointer_obj_base(const hazard_pointer_obj_base&) = default;
    hazard_pointer_obj_base(hazard_pointer_obj_base&&) = default;
    hazard_pointer_obj_base& operator=(const hazard_pointer_obj_base&) = default;
    hazard_pointer_obj_base& operator=(hazard_pointer_obj_base&&) = default;
    ~hazard_pointer_obj_base() = default;
  private:
    D deleter;      // exposition only
  };
}

[编辑] std::hazard_pointer

namespace std {
  class hazard_pointer {
  public:
    hazard_pointer() noexcept;
    hazard_pointer(hazard_pointer&&) noexcept;
    hazard_pointer& operator=(hazard_pointer&&) noexcept;
    ~hazard_pointer();
 
    bool empty() const noexcept;
    template<class T> T* protect(const atomic<T*>& src) noexcept;
    template<class T> bool try_protect(T*& ptr, const atomic<T*>& src) noexcept;
    template<class T> void reset_protection(const T* ptr) noexcept;
    void reset_protection(nullptr_t = nullptr) noexcept;
    void swap(hazard_pointer&) noexcept;
  };
}