Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::atomic_init

      From cppreference.com
      <cpp‎ |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
      atomic_init
      (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
       
      Defined in header<atomic>
      template<class T>

      void atomic_init
         (std::atomic<T>* obj,

           typenamestd::atomic<T>::value_type desired)noexcept;
      (1)(since C++11)
      (deprecated in C++20)
      template<class T>

      void atomic_init
         (volatilestd::atomic<T>* obj,

           typenamestd::atomic<T>::value_type desired)noexcept;
      (2)(since C++11)
      (deprecated in C++20)

      Initializes the default-constructed atomic objectobj with the valuedesired. The function is not atomic: concurrent access from another thread, even through an atomic operation, is a data race.

      Ifobj was not default-constructed, or this function is called twice on the sameobj, the behavior is undefined.

      Contents

      [edit]Parameters

      obj - pointer to an atomic object to initialize
      desired - the value to initialize atomic object with

      [edit]Return value

      (none)

      [edit]Notes

      This function is provided for compatibility with C. If the compatibility is not required,std::atomic may be initialized through their non-default constructors.

      [edit]Example

      This section is incomplete
      Reason: no example

      [edit]Defect reports

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

      DRApplied toBehavior as publishedCorrect behavior
      P0558R1C++11exact type match was required because
      T was deduced from multiple arguments
      T is only deduced
      fromobj

      [edit]See also

      (C++11)(deprecated in C++20)
      constant initialization of an atomic variable of static storage duration
      (function macro)[edit]
      constructs an atomic object
      (public member function ofstd::atomic<T>)[edit]
      C documentation foratomic_init
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/atomic/atomic_init&oldid=159434"

      [8]ページ先頭

      ©2009-2025 Movatter.jp