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.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

๋ธŒ๋ผ์šฐ์ € ํ˜ธํ™˜์„ฑ

๊ฐ™์ด ๋ณด๊ธฐ