Atomics.notify()

静态方法 Atomics.notify() 提醒一些在等待队列中休眠的代理。

注意:本操作仅在共享的 Int32Array 下可用。

语法

Atomics.notify(typedArray, index, count)

参数

typedArray
一个共享的  Int32Array
index
typedArray 中要唤醒的目标索引。
count
要通知的正在休眠的代理的数量。默认是  +Infinity

返回值

被唤醒的代理的数量。

异常

  • 若 typedArray 不是共享的 TypeError 异常。
  • 若 index 索引超出了 typedArray 的大小,则抛出一个 RangeError 异常。

示例

分配一个共享的 Int32Array

var sab = new SharedArrayBuffer(1024);
var int32 = new Int32Array(sab);

一个读线程会进入休眠并监视索引0处的值(默认为0)。只要索引0处的值不为0,读进程就会唤醒。但是,一旦写进程存储了一个新的值,写进程就会产生一个提醒并返回写入后的新值(123)。

Atomics.wait(int32, 0, 0);
console.log(int32[0]); // 123

写进程写入一个新值并告知等待进程已经写入成功了:

console.log(int32[0]); // 0;
Atomics.store(int32, 0, 123); 
Atomics.notify(int32, 0, 1);

规范

规范 状态 注释
ECMAScript Latest Draft (ECMA-262)
Atomics.notify
Draft Initial definition in ES2017.

浏览器兼容性

Update compatibility data on GitHub
Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
notify Chrome Full support 68
Full support 68
No support 60 — 63
Notes Alternate Name
Notes Chrome disabled SharedArrayBuffer on January 5, 2018 to help reduce the efficacy of speculative side-channel attacks. This was a temporary removal while mitigations were put in place.
Alternate Name Uses the non-standard name: wake
Edge No support No
Notes Alternate Name
No support No
Notes Alternate Name
Notes Support was removed to mitigate speculative execution side-channel attacks (Windows blog).
Alternate Name Uses the non-standard name: wake
Firefox Full support 63
Notes Disabled
Full support 63
Notes Disabled
Notes Support was disabled by default to mitigate speculative execution side-channel attacks (Mozilla Security Blog).
Disabled From version 63: this feature is behind the javascript.options.shared_memory preference (needs to be set to true). To change preferences in Firefox, visit about:config.
Full support 57
Notes Alternate Name Disabled
Notes Support was disabled by default to mitigate speculative execution side-channel attacks (Mozilla Security Blog).
Alternate Name Uses the non-standard name: wake
Disabled From version 57: this feature is behind the javascript.options.shared_memory preference (needs to be set to true). To change preferences in Firefox, visit about:config.
No support 55 — 57
No support 48 — 55
Disabled
Disabled From version 48 until version 55 (exclusive): this feature is behind the javascript.options.shared_memory preference (needs to be set to true). To change preferences in Firefox, visit about:config.
No support 46 — 48
Notes Alternate Name Disabled
Notes The count parameter defaults to 0 instead of the later-specified +Infinity.
Alternate Name Uses the non-standard name: futexWake
Disabled From version 46 until version 48 (exclusive): this feature is behind the javascript.options.shared_memory preference (needs to be set to true). To change preferences in Firefox, visit about:config.
IE No support No Opera No support No Safari No support 10.1 — ?
Alternate Name
No support 10.1 — ?
Alternate Name
Alternate Name Uses the non-standard name: wake
WebView Android No support 60 — 63
Notes Alternate Name
No support 60 — 63
Notes Alternate Name
Notes Chrome disabled SharedArrayBuffer on January 5, 2018 to help reduce the efficacy of speculative side-channel attacks. This is intended as a temporary measure until other mitigations are in place.
Alternate Name Uses the non-standard name: wake
Chrome Android No support 60 — 63
Notes Alternate Name
No support 60 — 63
Notes Alternate Name
Notes Chrome disabled SharedArrayBuffer on January 5, 2018 to help reduce the efficacy of speculative side-channel attacks. This is intended as a temporary measure until other mitigations are in place.
Alternate Name Uses the non-standard name: wake
Firefox Android Full support 63
Notes Disabled
Full support 63
Notes Disabled
Notes Support was disabled by default to mitigate speculative execution side-channel attacks (Mozilla Security Blog).
Disabled From version 63: this feature is behind the javascript.options.shared_memory preference (needs to be set to true). To change preferences in Firefox, visit about:config.
Full support 57
Notes Alternate Name Disabled
Notes Support was disabled by default to mitigate speculative execution side-channel attacks (Mozilla Security Blog).
Alternate Name Uses the non-standard name: wake
Disabled From version 57: this feature is behind the javascript.options.shared_memory preference (needs to be set to true). To change preferences in Firefox, visit about:config.
No support 55 — 57
No support 48 — 55
Disabled
Disabled From version 48 until version 55 (exclusive): this feature is behind the javascript.options.shared_memory preference (needs to be set to true). To change preferences in Firefox, visit about:config.
No support 46 — 48
Notes Alternate Name Disabled
Notes The count parameter defaults to 0 instead of the later-specified +Infinity.
Alternate Name Uses the non-standard name: futexWake
Disabled From version 46 until version 48 (exclusive): this feature is behind the javascript.options.shared_memory preference (needs to be set to true). To change preferences in Firefox, visit about:config.
Opera Android No support No Safari iOS No support No Samsung Internet Android No support No
Notes Alternate Name
No support No
Notes Alternate Name
Notes Chrome disabled SharedArrayBuffer on January 5, 2018 to help reduce the efficacy of speculative side-channel attacks. This is intended as a temporary measure until other mitigations are in place.
Alternate Name Uses the non-standard name: wake
nodejs Full support 8.10.0
Alternate Name
Full support 8.10.0
Alternate Name
Alternate Name Uses the non-standard name: wake

Legend

Full support  
Full support
No support  
No support
See implementation notes.
See implementation notes.
User must explicitly enable this feature.
User must explicitly enable this feature.
Uses a non-standard name.
Uses a non-standard name.

相关文档