atomic头文件编译_atomic
12/06/2019
本文內容
定義用于創建支持原子操作的類型的類和類模板。Defines classes and class templates to use to create types that support atomic operations.
語法Syntax
#include
備注Remarks
備注
在使用/clr: pure編譯的代碼中,此標頭被阻止。In code that's compiled by using /clr:pure, this header is blocked. 在 Visual Studio 2017 及更高版本中,不推薦使用 /clr: pure和 /clr: safe 。Both /clr:pure and /clr:safe are deprecated in Visual Studio 2017 and later versions.
一個原子操作有兩個關鍵屬性,幫助你使用多個線程正確操控對象,而無需使用互斥鎖。An atomic operation has two key properties that help you use multiple threads to correctly manipulate an object without using mutex locks.
由于原子操作是不可分的,因此,來自不同線程的同一對象的第二個原子操作只能在第一個原子操作之前或之后獲取該對象的狀態。Because an atomic operation is indivisible, a second atomic operation on the same object from a different thread can obtain the object's state only before or after the first atomic operation.
基于其 memory_order 參數,原子操作可以針對同一個線程中其他原子操作的影響可見性建立排序要求。Based on its memory_order argument, an atomic operation establishes ordering requirements for the visibility of the effects of other atomic operations in the same thread. 因此,它會抑制違反排序要求的編譯器優化。Consequently, it inhibits compiler optimizations that violate the ordering requirements.
在某些平臺上,如果不使用 mutex 鎖,可能無法有效地實施某些類型的原子操作。On some platforms, it might not be possible to efficiently implement atomic operations for some types without using mutex locks. 如果對該類型執行的原子操作都沒有使用鎖,則原子類型為無鎖。An atomic type is lock-free if no atomic operations on that type use locks.
C + + 11:在信號處理程序中,如果或為 true,則可以對對象執行原子操作 obj obj.is_lock_free() atomic_is_lock_free(x) 。C++11: In signal-handlers, you can perform atomic operations on an object obj if obj.is_lock_free() or atomic_is_lock_free(x) are true.
類atomic_flag提供保存標志的最小原子類型 bool 。The class atomic_flag provides a minimal atomic type that holds a bool flag. 其操作始終為無鎖操作。Its operations are always lock-free.
類模板 atomic 存儲其參數類型的對象 T ,并提供對該存儲值的原子訪問。The class template atomic stores an object of its argument type T and provides atomic access to that stored value. 你可以使用可通過 memcpy 復制的任何類型對該類進行實例化,并通過使用 memcmp 測試是否相等。You can instantiate it by using any type that can be copied by using memcpy and tested for equality by using memcmp. 特別是,你可以將其與滿足這些要求的用戶定義類型結合使用,在很多情況下是與浮點類型結合使用。In particular, you can use it with user-defined types that meet these requirements and, in many cases, with floating-point types.
另外,該模板還具有一套用于整型類型的專用化和用于指針的部分專用化。The template also has a set of specializations for integral types and a partial specialization for pointers. 這些專用化提供了無法通過主模板獲得的其他操作。These specializations provide additional operations that aren't available through the primary template.
指針專用化Pointer Specializations
atomic 部分專用化應用于所有指針類型。The atomic partial specializations apply to all pointer types. 它們提供用于指針算術的方法。They provide methods for pointer arithmetic.
整型專用化Integral Specializations
atomic 專用化將應用于所有整型類型。The atomic specializations apply to all integral types. 它們提供了無法通過主模板獲得的其他操作。They provide additional operations that aren't available through the primary template.
每個 atomic 類型都有一個對應的宏,你可以在 if directive 中使用該宏來確定編譯時對該類型執行的操作是否為無鎖。Each atomic type has a corresponding macro that you can use in an if directive to determine at compile time whether operations on that type are lock-free. 如果宏的值為零,則對該類型的操作不會無鎖。If the value of the macro is zero, operations on the type aren't lock-free. 如果值為 1,則操作可能為無鎖,且需要進行運行時檢查。If the value is 1, operations might be lock-free, and a runtime check is required. 如果值為 2,操作為無鎖。If the value is 2, operations are lock-free. 可以使用函數 atomic_is_lock_free 確定在運行時對類型執行的操作是否為無鎖。You can use the function atomic_is_lock_free to determine at runtime whether operations on the type are lock-free.
對于每個整型類型,都有一個對應的命名原子類型,用于管理該整型類型的對象。For each of the integral types, there's a corresponding named atomic type that manages an object of that integral type. 每個 atomic_integral 類型都具有與 atomic 的相應實例化相同的成員函數集,并且可以傳遞至任何非成員原子函數。Each atomic_integral type has the same set of member functions as the corresponding instantiation of atomic and can be passed to any of the non-member atomic functions.
atomic_integral 類型atomic_integral Type
整型類型Integral Type
atomic_is_lock_free 宏atomic_is_lock_free Macro
atomic_char
char
ATOMIC_CHAR_LOCK_FREEATOMIC_CHAR_LOCK_FREE
atomic_schar
signed char
ATOMIC_CHAR_LOCK_FREEATOMIC_CHAR_LOCK_FREE
atomic_uchar
unsigned char
ATOMIC_CHAR_LOCK_FREEATOMIC_CHAR_LOCK_FREE
atomic_char16_t
char16_t
ATOMIC_CHAR16_T_LOCK_FREEATOMIC_CHAR16_T_LOCK_FREE
atomic_char32_t
char32_t
ATOMIC_CHAR32_T_LOCK_FREEATOMIC_CHAR32_T_LOCK_FREE
atomic_wchar_t
wchar_t
ATOMIC_WCHAR_T_LOCK_FREEATOMIC_WCHAR_T_LOCK_FREE
atomic_short
short
ATOMIC_SHORT_LOCK_FREEATOMIC_SHORT_LOCK_FREE
atomic_ushort
unsigned short
ATOMIC_SHORT_LOCK_FREEATOMIC_SHORT_LOCK_FREE
atomic_int
int
ATOMIC_INT_LOCK_FREEATOMIC_INT_LOCK_FREE
atomic_uint
unsigned int
ATOMIC_INT_LOCK_FREEATOMIC_INT_LOCK_FREE
atomic_long
long
ATOMIC_LONG_LOCK_FREEATOMIC_LONG_LOCK_FREE
atomic_ulong
unsigned long
ATOMIC_LONG_LOCK_FREEATOMIC_LONG_LOCK_FREE
atomic_llong
long long
ATOMIC_LLONG_LOCK_FREEATOMIC_LLONG_LOCK_FREE
atomic_ullong
unsigned long long
ATOMIC_LLONG_LOCK_FREEATOMIC_LLONG_LOCK_FREE
在標頭中定義的某些類型的原子模板專用化 Typedef 名稱 。Typedef names exist for specializations of the atomic template for some of the types that are defined in the header .
原子類型Atomic Type
Typedef 名稱Typedef Name
atomic_int8_t
atomic
atomic_uint8_t
atomic
atomic_int16_t
atomic
atomic_uint16_t
atomic
atomic_int32_t
atomic
atomic_uint32_t
atomic
atomic_int64_t
atomic
atomic_uint64_t
atomic
atomic_int_least8_t
atomic
atomic_uint_least8_t
atomic
atomic_int_least16_t
atomic
atomic_uint_least16_t
atomic
atomic_int_least32_t
atomic
atomic_uint_least32_t
atomic
atomic_int_least64_t
atomic
atomic_uint_least64_t
atomic
atomic_int_fast8_t
atomic
atomic_uint_fast8_t
atomic
atomic_int_fast16_t
atomic
atomic_uint_fast16_
atomic
atomic_int_fast32_t
atomic
atomic_uint_fast32_t
atomic
atomic_int_fast64_t
atomic
atomic_uint_fast64_t
atomic
atomic_intptr_t
atomic
atomic_uintptr_t
atomic
atomic_size_t
atomic
atomic_ptrdiff_t
atomic
atomic_intmax_t
atomic
atomic_uintmax_t
atomic
結構Structs
名稱Name
描述Description
描述對存儲值執行原子操作的對象。Describes an object that performs atomic operations on a stored value.
描述一個對象,該對象以原子方式設置并清除 bool 標志。Describes an object that atomically sets and clears a bool flag.
枚舉Enums
名稱Name
描述Description
為內存位置上的同步操作提供符號名稱。Supplies symbolic names for synchronization operations on memory locations. 這些操作將影響一個線程內的分配如何在另一個線程內變得可見。These operations affect how assignments in one thread become visible in another.
函數Functions
在下面的列表中,不以結尾的函數 _explicit 具有對應的語義 _explicit ,只不過它們具有的隱式memory_order自變量 memory_order_seq_cst 。In the following list, the functions that don't end in _explicit have the semantics of the corresponding _explicit, except that they have the implicit memory_order arguments of memory_order_seq_cst.
名稱Name
描述Description
執行原子比較和交換操作。Performs an atomic compare and exchange operation.
執行弱原子比較和交換操作。Performs a weak atomic compare and exchange operation.
替換存儲值。Replaces a stored value.
將指定的值添加到現有存儲值。Adds a specified value to an existing stored value.
將指定的值添加到現有存儲值。Adds a specified value to an existing stored value.
對指定值和現有存儲值執行按位 and。Performs a bitwise and on a specified value and an existing stored value.
對指定值和現有存儲值執行按位 and。Performs a bitwise and on a specified value and an existing stored value.
對指定值和現有存儲值執行按位 or。Performs a bitwise or on a specified value and an existing stored value.
對指定值和現有存儲值執行按位 or。Performs a bitwise or on a specified value and an existing stored value.
從現有存儲值減去指定的值。Subtracts a specified value from an existing stored value.
從現有存儲值減去指定的值。Subtracts a specified value from an existing stored value.
對指定值和現有存儲值執行按位 exclusive or。Performs a bitwise exclusive or on a specified value and an existing stored value.
對指定值和現有存儲值執行按位 exclusive or。Performs a bitwise exclusive or on a specified value and an existing stored value.
將對象中的標志設置 atomic_flag 為 false 。Sets the flag in an atomic_flag object to false.
將對象中的標志設置 atomic_flag 為 false 。Sets the flag in an atomic_flag object to false.
將對象中的標志設置 atomic_flag 為 true 。Sets the flag in an atomic_flag object to true.
將對象中的標志設置 atomic_flag 為 true 。Sets the flag in an atomic_flag object to true.
設置 atomic 對象中存儲的值。Sets the stored value in an atomic object.
指定對指定對象執行的原子操作是否為無鎖。Specifies whether atomic operations on a specified object are lock-free.
以原子方式檢索一個值。Atomically retrieves a value.
以原子方式檢索一個值。Atomically retrieves a value.
充當 fence,用于在調用線程中信號處理程序在同一線程中執行的 fence 之間建立內存排序要求。Acts as a fence that establishes memory ordering requirements between fences in a calling thread that has signal handlers executed in the same thread.
以原子方式存儲一個值。Atomically stores a value.
充當就其他 fence 建立內存排序要求的 fence。Acts as a fence that establishes memory ordering requirements with respect to other fences.
中斷可能的依賴關系鏈。Breaks a possible dependency chain.
另請參閱See also
總結
以上是生活随笔為你收集整理的atomic头文件编译_atomic的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2008年国际十大财经新闻
- 下一篇: Html+Css+Js轮播图实现