From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../global_objects/atomics/exchange/index.html | 85 ++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 files/zh-cn/web/javascript/reference/global_objects/atomics/exchange/index.html (limited to 'files/zh-cn/web/javascript/reference/global_objects/atomics/exchange/index.html') diff --git a/files/zh-cn/web/javascript/reference/global_objects/atomics/exchange/index.html b/files/zh-cn/web/javascript/reference/global_objects/atomics/exchange/index.html new file mode 100644 index 0000000000..4502bf8a52 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/atomics/exchange/index.html @@ -0,0 +1,85 @@ +--- +title: Atomics.exchange() +slug: Web/JavaScript/Reference/Global_Objects/Atomics/exchange +tags: + - Atmoics + - Experimental + - JavaScript + - Method + - 共享内存 + - 实验性 +translation_of: Web/JavaScript/Reference/Global_Objects/Atomics/exchange +--- +
{{JSRef}} {{SeeCompatTable}}
+ +

Atomics.exchange() 静态方法会用给定的值替换掉数组上的值,然后返回数组的旧值。此原子操作保证在写上修改的值之前不会发生其他写操作。

+ +
{{EmbedInteractiveExample("pages/js/atomics-exchange.html")}}
+ + + +

语法

+ +
Atomics.exchange(typedArray, index, value)
+
+ +

参数

+ +
+
typedArray
+
一个共享的整型 typed array。例如 {{jsxref("Int8Array")}},{{jsxref("Uint8Array")}},{{jsxref("Int16Array")}},{{jsxref("Uint16Array")}},{{jsxref("Int32Array")}},或 {{jsxref("Uint32Array")}}。
+
index
+
被替换的 typedArray 值的索引。
+
value
+
去替换的值。
+
+ +

返回值

+ +

给定位置的旧值(typedArray[index]).

+ +

错误

+ + + +

示例

+ +
var sab = new SharedArrayBuffer(1024);
+var ta = new Uint8Array(sab);
+
+Atomics.exchange(ta, 0, 12); // returns 0, the old value
+Atomics.load(ta, 0); // 12
+ +

规范

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Shared Memory', '#Atomics.exchange', 'Atomics.exchange')}}{{Spec2('Shared Memory')}}Initial definition.
+ +

浏览器支持

+ + + +

{{Compat("javascript.builtins.Atomics.exchange")}}

+ +

相关

+ + -- cgit v1.2.3-54-g00ecf