blob: 83a4c4087217e58627475fab5fec6ba2705cd166 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
---
title: Atomics
slug: Web/JavaScript/Reference/Global_Objects/Atomics
translation_of: Web/JavaScript/Reference/Global_Objects/Atomics
browser-compat: javascript.builtins.Atomics
---
<div>{{JSRef}} {{SeeCompatTable}}</div>
<div><strong>Atomics 오브젝트</strong>는 atomic operations 정적메소드로서 제공됩니다. 다음과 같은 오브젝트와 함께 {{jsxref("SharedArrayBuffer")}} 사용합니다.</div>
<p>Atomic operations Atomic Module을 인스톨해야합니다. 다른 global objects들과 다르게 Atomic은 constructor가 아닙니다. <strong>new operator</strong>를 사용하면 안되고 invoke Atomics object 함수로 사용하면됩니다. Atomics의 속성과 함수들은 static입니다. (as is the case with the {{jsxref("Math")}} object, for example).</p>
<h2 id="Methods">Methods</h2>
<h3 id="Atomic_operations">Atomic operations</h3>
<p>메모리가 공유되었을때, 멀티쓰레드는 메모리안에 같은 데이터들을 읽거나 쓸 수 있습니다.<br>
Atomic operations은 예측 가능한 값을 쓰고 읽으며 다음 작업이 시작되기 전에 작업이 완료되고,작업이 중단되지 않도록합니다.</p>
<dl>
<dt>{{jsxref("Atomics.add()")}}</dt>
<dd>Adds a given value at a given position in the array. Returns the old value at that position.</dd>
<dt>{{jsxref("Atomics.and()")}}</dt>
<dd>Computes a bitwise AND at a given position in the array. Returns the old value at that position.</dd>
<dt>{{jsxref("Atomics.compareExchange()")}}</dt>
<dd>Stores a given value at a given position in the array, if it equals a given value. Returns the old value.</dd>
<dt>{{jsxref("Atomics.exchange()")}}</dt>
<dd>Stores a given value at a given position in the array. Returns the old value.</dd>
</dl>
<dl>
<dt>{{jsxref("Atomics.load()")}}</dt>
<dd>Returns the value at the given position in the array.</dd>
<dt>{{jsxref("Atomics.or()")}}</dt>
<dd>Computes a bitwise OR at a given position in the array. Returns the old value at that position.</dd>
<dt>{{jsxref("Atomics.store()")}}</dt>
<dd>Stores a given value at the given position in the array. Returns the value.</dd>
<dt>{{jsxref("Atomics.sub()")}}</dt>
<dd>Subtracts a given value at a given position in the array. Returns the old value at that position.</dd>
<dt>{{jsxref("Atomics.xor()")}}</dt>
<dd>Computes a bitwise XOR at a given position in the array. Returns the old value at that position.</dd>
</dl>
<h3 id="Wait_and_wake">Wait and wake</h3>
<p>The <code>wait()</code> and <code>wake()</code> methods are modeled on Linux futexes ("fast user-space mutex") and provide ways for waiting until a certain condition becomes true and are typically used as blocking constructs.</p>
<dl>
<dt>{{jsxref("Atomics.wait()")}}</dt>
<dd>
<p>Verifies that a given position in the array still contains a given value and sleeps awaiting or times out. Returns either <code>"ok"</code>, <code>"not-equal"</code>, or <code>"timed-out"</code>. If waiting is not allowed in the calling agent then it throws an Error exception (most browsers will not allow <code>wait()</code> on the browser's main thread).</p>
</dd>
<dt>{{jsxref("Atomics.wake()")}}</dt>
<dd>Wakes up some agents that are sleeping in the wait queue on the given array position. Returns the number of agents that were woken up.</dd>
<dt>{{jsxref("Atomics.isLockFree()", "Atomics.isLockFree(size)")}}</dt>
<dd>
<p>An optimization primitive that can be used to determine whether to use locks or atomic operations. Returns <code>true</code>, if an atomic operation on arrays of the given element size will be implemented using a hardware atomic operation (as opposed to a lock). Experts only.</p>
</dd>
</dl>
<h2 id="specifications">명세</h2>
<p>{{Specifications}}</p>
<h2 id="browser_compatibility">브라우저 호환성</h2>
<p>{{Compat}}</p>
<h2 id="See_also">See also</h2>
<ul>
<li>{{jsxref("ArrayBuffer")}}</li>
<li><a href="/en-US/docs/Web/JavaScript/Typed_arrays">JavaScript typed arrays</a></li>
<li><a href="/en-US/docs/Web/API/Web_Workers_API">Web Workers</a></li>
<li><a href="https://github.com/lars-t-hansen/parlib-simple">parlib-simple </a>– a simple library providing synchronization and work distribution abstractions.</li>
<li><a href="https://github.com/tc39/ecmascript_sharedmem/blob/master/TUTORIAL.md">Shared Memory – a brief tutorial</a></li>
<li><a href="https://hacks.mozilla.org/2016/05/a-taste-of-javascripts-new-parallel-primitives/">A Taste of JavaScript’s New Parallel Primitives – Mozilla Hacks</a></li>
</ul>
|