[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Atomics [Back]  [Original]

Atomics - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Atomics

Baseline Widely available *

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2021 12.

* Some parts of this feature may have varying levels of support.

Atomics (Atomic operation, ) . SharedArrayBuffer ArrayBuffer .

In this article

Atomic . Atomics , new Atomics . Math Atomics .

. , .

Wait notify

wait() notify() Linux (futex)(" (mutex)") .

Atomics[@@toStringTag]

@@toStringTag "Atomics" . Object.prototype.toString() .

Atomics.add()

. .

Atomics.and()

AND . .

Atomics.compareExchange()

. .

Atomics.exchange()

. .

Atomics.isLockFree(size)

atomic . atomic atomic ( ) true . .

Atomics.load()

.

Atomics.notify()

. .

Atomics.or()

OR . .

Atomics.store()

. .

Atomics.sub()

. .

Atomics.wait()

. "ok", "not-equal" "timed-out" . . ( wait() .)

Atomics.waitAsync()

(, Atomics.wait ) .

Atomics.xor()

XOR . .

Atomic

js
const sab = new SharedArrayBuffer(1024);
const ta = new Uint8Array(sab);

ta[0]; // 0
ta[0] = 5; // 5

Atomics.add(ta, 0, 12); // 5
Atomics.load(ta, 0); // 17

Atomics.and(ta, 0, 1); // 17
Atomics.load(ta, 0); // 1

Atomics.compareExchange(ta, 0, 5, 12); // 1
Atomics.load(ta, 0); // 1

Atomics.exchange(ta, 0, 12); // 1
Atomics.load(ta, 0); // 12

Atomics.isLockFree(1); // true
Atomics.isLockFree(2); // true
Atomics.isLockFree(3); // false
Atomics.isLockFree(4); // true

Atomics.or(ta, 0, 1); // 12
Atomics.load(ta, 0); // 13

Atomics.store(ta, 0, 12); // 12

Atomics.sub(ta, 0, 2); // 12
Atomics.load(ta, 0); // 10

Atomics.xor(ta, 0, 1); // 10
Atomics.load(ta, 0); // 11

Waiting notifying

Int32Array

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

0 0 sleep . . . (123)

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

.

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

Specification
ECMAScript 2027 LanguageSpecification
# sec-atomics-object


Web Proxy Viewer  |  New URL  |  Original Page