Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::atomic<T>::atomic

      From cppreference.com
      <cpp‎ |atomic‎ |atomic
       
       
      Concurrency support library
      Threads
      (C++11)
      (C++20)
      this_thread namespace
      (C++11)
      (C++11)
      (C++11)
      Cooperative cancellation
      Mutual exclusion
      Generic lock management
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      Condition variables
      (C++11)
      Semaphores
      Latches and Barriers
      (C++20)
      (C++20)
      Futures
      (C++11)
      (C++11)
      (C++11)
      Safe reclamation
      Hazard pointers
      Atomic types
      (C++11)
      (C++20)
      Initialization of atomic types
      (C++11)(deprecated in C++20)
      (C++11)(deprecated in C++20)
      Memory ordering
      (C++11)(deprecated in C++26)
      Free functions for atomic operations
      Free functions for atomic flags
       
       
      (1)
      atomic()noexcept=default;
      (since C++11)
      (until C++20)
      constexpr atomic()noexcept(std::is_nothrow_default_constructible_v<T>);
      (since C++20)
      constexpr atomic( T desired)noexcept;
      (2)(since C++11)
      atomic(const atomic&)= delete;
      (3)(since C++11)

      Constructs a new atomic variable.

      1) The default constructor is trivial: no initialization takes place other thanzero initialization of static and thread-local objects.
      std::atomic_init may be used to complete initialization.
      (until C++20)
      1) Value-initializes the underlying object (i.e. withT()). The initialization is not atomic.
      This overload participates in overload resolution only ifstd::is_default_constructible_v<T> istrue.
      (since C++20)
      2) Initializes the underlying object withdesired. The initialization is not atomic.
      3) Atomic variables are notCopyConstructible.

      [edit]Parameters

      desired - value to initialize with

      [edit]Notes

      The default-initializedstd::atomic<T> does not contain aT object, and its only valid uses are destruction and initialization bystd::atomic_init, seeLWG issue 2334.

      (until C++20)

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 4169C++20std::is_default_constructible_v could report false positivethe default constructor is constrained
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/atomic/atomic/atomic&oldid=177917"

      [8]ページ先頭

      ©2009-2025 Movatter.jp