日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

atomic头文件编译_atomic

發(fā)布時(shí)間:2023/12/16 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 atomic头文件编译_atomic 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

12/06/2019

本文內(nèi)容

定義用于創(chuàng)建支持原子操作的類(lèi)型的類(lèi)和類(lèi)模板。Defines classes and class templates to use to create types that support atomic operations.

語(yǔ)法Syntax

#include

備注Remarks

備注

在使用/clr: pure編譯的代碼中,此標(biāo)頭被阻止。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.

一個(gè)原子操作有兩個(gè)關(guān)鍵屬性,幫助你使用多個(gè)線程正確操控對(duì)象,而無(wú)需使用互斥鎖。An atomic operation has two key properties that help you use multiple threads to correctly manipulate an object without using mutex locks.

由于原子操作是不可分的,因此,來(lái)自不同線程的同一對(duì)象的第二個(gè)原子操作只能在第一個(gè)原子操作之前或之后獲取該對(duì)象的狀態(tài)。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 參數(shù),原子操作可以針對(duì)同一個(gè)線程中其他原子操作的影響可見(jiàn)性建立排序要求。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. 因此,它會(huì)抑制違反排序要求的編譯器優(yōu)化。Consequently, it inhibits compiler optimizations that violate the ordering requirements.

在某些平臺(tái)上,如果不使用 mutex 鎖,可能無(wú)法有效地實(shí)施某些類(lèi)型的原子操作。On some platforms, it might not be possible to efficiently implement atomic operations for some types without using mutex locks. 如果對(duì)該類(lèi)型執(zhí)行的原子操作都沒(méi)有使用鎖,則原子類(lèi)型為無(wú)鎖。An atomic type is lock-free if no atomic operations on that type use locks.

C + + 11:在信號(hào)處理程序中,如果或?yàn)?true,則可以對(duì)對(duì)象執(zhí)行原子操作 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.

類(lèi)atomic_flag提供保存標(biāo)志的最小原子類(lèi)型 bool 。The class atomic_flag provides a minimal atomic type that holds a bool flag. 其操作始終為無(wú)鎖操作。Its operations are always lock-free.

類(lèi)模板 atomic 存儲(chǔ)其參數(shù)類(lèi)型的對(duì)象 T ,并提供對(duì)該存儲(chǔ)值的原子訪問(wèn)。The class template atomic stores an object of its argument type T and provides atomic access to that stored value. 你可以使用可通過(guò) memcpy 復(fù)制的任何類(lèi)型對(duì)該類(lèi)進(jìn)行實(shí)例化,并通過(guò)使用 memcmp 測(cè)試是否相等。You can instantiate it by using any type that can be copied by using memcpy and tested for equality by using memcmp. 特別是,你可以將其與滿足這些要求的用戶定義類(lèi)型結(jié)合使用,在很多情況下是與浮點(diǎn)類(lèi)型結(jié)合使用。In particular, you can use it with user-defined types that meet these requirements and, in many cases, with floating-point types.

另外,該模板還具有一套用于整型類(lèi)型的專(zhuān)用化和用于指針的部分專(zhuān)用化。The template also has a set of specializations for integral types and a partial specialization for pointers. 這些專(zhuān)用化提供了無(wú)法通過(guò)主模板獲得的其他操作。These specializations provide additional operations that aren't available through the primary template.

指針專(zhuān)用化Pointer Specializations

atomic 部分專(zhuān)用化應(yīng)用于所有指針類(lèi)型。The atomic partial specializations apply to all pointer types. 它們提供用于指針?biāo)阈g(shù)的方法。They provide methods for pointer arithmetic.

整型專(zhuān)用化Integral Specializations

atomic 專(zhuān)用化將應(yīng)用于所有整型類(lèi)型。The atomic specializations apply to all integral types. 它們提供了無(wú)法通過(guò)主模板獲得的其他操作。They provide additional operations that aren't available through the primary template.

每個(gè) atomic 類(lèi)型都有一個(gè)對(duì)應(yīng)的宏,你可以在 if directive 中使用該宏來(lái)確定編譯時(shí)對(duì)該類(lèi)型執(zhí)行的操作是否為無(wú)鎖。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. 如果宏的值為零,則對(duì)該類(lèi)型的操作不會(huì)無(wú)鎖。If the value of the macro is zero, operations on the type aren't lock-free. 如果值為 1,則操作可能為無(wú)鎖,且需要進(jìn)行運(yùn)行時(shí)檢查。If the value is 1, operations might be lock-free, and a runtime check is required. 如果值為 2,操作為無(wú)鎖。If the value is 2, operations are lock-free. 可以使用函數(shù) atomic_is_lock_free 確定在運(yùn)行時(shí)對(duì)類(lèi)型執(zhí)行的操作是否為無(wú)鎖。You can use the function atomic_is_lock_free to determine at runtime whether operations on the type are lock-free.

對(duì)于每個(gè)整型類(lèi)型,都有一個(gè)對(duì)應(yīng)的命名原子類(lèi)型,用于管理該整型類(lèi)型的對(duì)象。For each of the integral types, there's a corresponding named atomic type that manages an object of that integral type. 每個(gè) atomic_integral 類(lèi)型都具有與 atomic 的相應(yīng)實(shí)例化相同的成員函數(shù)集,并且可以傳遞至任何非成員原子函數(shù)。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 類(lèi)型atomic_integral Type

整型類(lèi)型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

在標(biāo)頭中定義的某些類(lèi)型的原子模板專(zhuān)用化 Typedef 名稱(chēng) 。Typedef names exist for specializations of the atomic template for some of the types that are defined in the header .

原子類(lèi)型Atomic Type

Typedef 名稱(chēng)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

結(jié)構(gòu)Structs

名稱(chēng)Name

描述Description

描述對(duì)存儲(chǔ)值執(zhí)行原子操作的對(duì)象。Describes an object that performs atomic operations on a stored value.

描述一個(gè)對(duì)象,該對(duì)象以原子方式設(shè)置并清除 bool 標(biāo)志。Describes an object that atomically sets and clears a bool flag.

枚舉Enums

名稱(chēng)Name

描述Description

為內(nèi)存位置上的同步操作提供符號(hào)名稱(chēng)。Supplies symbolic names for synchronization operations on memory locations. 這些操作將影響一個(gè)線程內(nèi)的分配如何在另一個(gè)線程內(nèi)變得可見(jiàn)。These operations affect how assignments in one thread become visible in another.

函數(shù)Functions

在下面的列表中,不以結(jié)尾的函數(shù) _explicit 具有對(duì)應(yīng)的語(yǔ)義 _explicit ,只不過(guò)它們具有的隱式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.

名稱(chēng)Name

描述Description

執(zhí)行原子比較和交換操作。Performs an atomic compare and exchange operation.

執(zhí)行弱原子比較和交換操作。Performs a weak atomic compare and exchange operation.

替換存儲(chǔ)值。Replaces a stored value.

將指定的值添加到現(xiàn)有存儲(chǔ)值。Adds a specified value to an existing stored value.

將指定的值添加到現(xiàn)有存儲(chǔ)值。Adds a specified value to an existing stored value.

對(duì)指定值和現(xiàn)有存儲(chǔ)值執(zhí)行按位 and。Performs a bitwise and on a specified value and an existing stored value.

對(duì)指定值和現(xiàn)有存儲(chǔ)值執(zhí)行按位 and。Performs a bitwise and on a specified value and an existing stored value.

對(duì)指定值和現(xiàn)有存儲(chǔ)值執(zhí)行按位 or。Performs a bitwise or on a specified value and an existing stored value.

對(duì)指定值和現(xiàn)有存儲(chǔ)值執(zhí)行按位 or。Performs a bitwise or on a specified value and an existing stored value.

從現(xiàn)有存儲(chǔ)值減去指定的值。Subtracts a specified value from an existing stored value.

從現(xiàn)有存儲(chǔ)值減去指定的值。Subtracts a specified value from an existing stored value.

對(duì)指定值和現(xiàn)有存儲(chǔ)值執(zhí)行按位 exclusive or。Performs a bitwise exclusive or on a specified value and an existing stored value.

對(duì)指定值和現(xiàn)有存儲(chǔ)值執(zhí)行按位 exclusive or。Performs a bitwise exclusive or on a specified value and an existing stored value.

將對(duì)象中的標(biāo)志設(shè)置 atomic_flag 為 false 。Sets the flag in an atomic_flag object to false.

將對(duì)象中的標(biāo)志設(shè)置 atomic_flag 為 false 。Sets the flag in an atomic_flag object to false.

將對(duì)象中的標(biāo)志設(shè)置 atomic_flag 為 true 。Sets the flag in an atomic_flag object to true.

將對(duì)象中的標(biāo)志設(shè)置 atomic_flag 為 true 。Sets the flag in an atomic_flag object to true.

設(shè)置 atomic 對(duì)象中存儲(chǔ)的值。Sets the stored value in an atomic object.

指定對(duì)指定對(duì)象執(zhí)行的原子操作是否為無(wú)鎖。Specifies whether atomic operations on a specified object are lock-free.

以原子方式檢索一個(gè)值。Atomically retrieves a value.

以原子方式檢索一個(gè)值。Atomically retrieves a value.

充當(dāng) fence,用于在調(diào)用線程中信號(hào)處理程序在同一線程中執(zhí)行的 fence 之間建立內(nèi)存排序要求。Acts as a fence that establishes memory ordering requirements between fences in a calling thread that has signal handlers executed in the same thread.

以原子方式存儲(chǔ)一個(gè)值。Atomically stores a value.

充當(dāng)就其他 fence 建立內(nèi)存排序要求的 fence。Acts as a fence that establishes memory ordering requirements with respect to other fences.

中斷可能的依賴(lài)關(guān)系鏈。Breaks a possible dependency chain.

另請(qǐng)參閱See also

總結(jié)

以上是生活随笔為你收集整理的atomic头文件编译_atomic的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。