aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/atomics/islockfree/index.html
blob: be8b32b587b50bae5690e69bdc319d9aa2e25dbf (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
---
title: Atomics.isLockFree()
slug: Web/JavaScript/Reference/Global_Objects/Atomics/isLockFree
translation_of: Web/JavaScript/Reference/Global_Objects/Atomics/isLockFree
---
<div>{{JSRef}} {{SeeCompatTable}}</div>

<p>静态方法 <code><strong>Atomics</strong></code><strong><code>.isLockFree()</code></strong> 用于校验是否能够使用原子操作的<code><a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/BYTES_PER_ELEMENT" title="TypedArray.BYTES_PER_ELEMENT 属性代表了强类型数组中每个元素所占用的字节数。">TypedArray</a></code>的标准字节长度之一. 若该字节长度为可处理的TypedArray标准字节长度之一则返回  <code>true.</code>  TypedArray的标准字节长度参见 <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/BYTES_PER_ELEMENT">BYTES_PER_ELEMENT</a></p>

<div>{{EmbedInteractiveExample("pages/js/atomics-islockfree.html")}}</div>



<h2 id="语法">语法</h2>

<pre class="syntaxbox">Atomics.isLockFree(size)
</pre>

<h3 id="参数">参数</h3>

<dl>
 <dt><code>size</code></dt>
 <dd>整形.字节长度,通常为<a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/BYTES_PER_ELEMENT" title="TypedArray.BYTES_PER_ELEMENT 属性代表了强类型数组中每个元素所占用的字节数。"><code>TypedArray.BYTES_PER_ELEMENT</code></a></dd>
</dl>

<h3 id="返回值">返回值</h3>

<p> {{jsxref("Boolean")}} 是否为能够使用原子操作的<code><a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/BYTES_PER_ELEMENT" title="TypedArray.BYTES_PER_ELEMENT 属性代表了强类型数组中每个元素所占用的字节数。">TypedArray</a></code>的标准字节长度之一.</p>

<h2 id="示例">示例</h2>

<pre class="brush: js">Atomics.isLockFree(1); // true
Atomics.isLockFree(2); // true
Atomics.isLockFree(3); // false
Atomics.isLockFree(4); // true
Atomics.isLockFree(5); // false
Atomics.isLockFree(6); // false
Atomics.isLockFree(7); // false
Atomics.isLockFree(8); // false
Atomics.isLockFree(<code>Float64Array.BYTES_PER_ELEMENT</code>); // false,<code>Atomics方法无法处理Float64Array</code></pre>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('Shared Memory', '#Atomics.isLockFree', 'Atomics.isLockFree')}}</td>
   <td>{{Spec2('Shared Memory')}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>



<p>{{Compat("javascript.builtins.Atomics.isLockFree")}}</p>

<h2 id="See_also">See also</h2>

<ul>
 <li>{{jsxref("Atomics")}}</li>
</ul>