Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

Atomics.notify()

BaselineWidely available

TheAtomics.notify() staticmethod notifies up some agents that are sleeping in the wait queue.

Note:This operation only works with anInt32Array orBigInt64Array that views aSharedArrayBuffer.It will return0 on non-sharedArrayBuffer objects.

Syntax

js
Atomics.notify(typedArray, index, count)

Parameters

typedArray

AnInt32Array orBigInt64Array that views aSharedArrayBuffer.

index

The position in thetypedArray to wake up on.

countOptional

The number of sleeping agents to notify. Defaults toInfinity.

Return value

Returns the number of woken up agents, or0 iftypedArray is a view on a non-sharedArrayBuffer.

Exceptions

TypeError

Thrown iftypedArray is not anInt32Array orBigInt64Array.

RangeError

Thrown ifindex is out of bounds in thetypedArray.

Examples

Usingnotify

Given a sharedInt32Array:

js
const sab = new SharedArrayBuffer(1024);const int32 = new Int32Array(sab);

A reading thread is sleeping and waiting on location 0 because the providedvalue matches what is stored at the providedindex.The reading thread will not move on until the writing thread has calledAtomics.notify() on position 0 of the providedtypedArray.Note that if, after being woken up, the value of location 0 has not been changed by the writing thread, the reading thread willnot go back to sleep, but will continue on.

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

A writing thread stores a new value and notifies the waiting thread once it haswritten:

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

Specifications

Specification
ECMAScript® 2026 Language Specification
# sec-atomics.notify

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp