Atomics.add()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itโs been available across browsers since โจ2021๋ 12์โฉ.
Atomics.add()
์ ์ ๋ฉ์๋๋ ๋ฐฐ์ด์ ์ง์ ๋ ์์น์ ์ง์ ๋ ๊ฐ์ ์ถ๊ฐํ๊ณ ํด๋น ์์น์ ์ด์ ๊ฐ์ ๋ฐํํฉ๋๋ค.
์ด ์ํ ๋ฏน ์ฐ์ฐ์ ์์ ๋ ๊ฐ ์ฐ๊ธฐ๊ฐ ์๋ฃ๋๊ธฐ ์ ๊น์ง ๋ค๋ฅธ ์ฐ๊ธฐ๊ฐ ๋ฐ์ํ์ง ์๋๋ก ๋ณด์ฅํฉ๋๋ค.
์๋ํด ๋ณด๊ธฐ
// Create a SharedArrayBuffer with a size in bytes
const buffer = new SharedArrayBuffer(16);
const uint8 = new Uint8Array(buffer);
uint8[0] = 7;
// 7 + 2 = 9
console.log(Atomics.add(uint8, 0, 2));
// Expected output: 7
console.log(Atomics.load(uint8, 0));
// Expected output: 9
๊ตฌ๋ฌธ
js
Atomics.add(typedArray, index, value)
๋งค๊ฐ๋ณ์
typedArray
-
์ ์ํ ๋ฐฐ์ด.
Int8Array
,Uint8Array
,Int16Array
,Uint16Array
,Int32Array
,Uint32Array
,BigInt64Array
,BigUint64Array
์ค ํ๋. index
-
value
๋ฅผ ๋ํtypedArray
๋ด์ ์์น. value
-
๋ํ ์ซ์.
๋ฐํ ๊ฐ
์ฃผ์ด์ง ์์น์ ์์ ๊ฐ(typedArray[index]
).
์์ธ
typedArray
๊ฐ ํ์ฉ๋ ์ ์ํ์ด ์๋ ๊ฒฝ์ฐTypeError
๊ฐ ๋ฐ์ํฉ๋๋ค.index
๊ฐtypedArray
์ ๋ฒ์๋ฅผ ๋ฒ์ด๋ ๊ฒฝ์ฐRangeError
๊ฐ ๋ฐ์ํฉ๋๋ค.
์์
add() ์ฌ์ฉํ๊ธฐ
js
const sab = new SharedArrayBuffer(1024);
const ta = new Uint8Array(sab);
Atomics.add(ta, 0, 12); // ์์ ๊ฐ์ธ 0์ ๋ฐํํฉ๋๋ค.
Atomics.load(ta, 0); // 12
๋ช ์ธ์
Specification |
---|
ECMAScriptยฎ 2026 Language Specification # sec-atomics.add |
๋ธ๋ผ์ฐ์ ํธํ์ฑ
Loadingโฆ