Atomics.isLockFree() - JavaScript | MDN
Try it
console.log(Atomics.isLockFree(3));
// 3 is not one of the BYTES_PER_ELEMENT values
// Expected output: false
console.log(Atomics.isLockFree(4));
// 4 is one of the BYTES_PER_ELEMENT values
// Expected output: true
Syntax
js
Atomics.isLockFree(size)
Parameters
size-
The size in bytes to check.
Return value
A true or false value indicating whether the operation is lock free.
- Always
trueifsizeis 4, because all known platforms support 4-byte atomic operations. - Always
falseif the given size is not one of theBYTES_PER_ELEMENTproperty of integer TypedArray types.
Examples
Using Atomics.isLockFree()
js
Atomics.isLockFree(1); // true (platform-dependent)
Atomics.isLockFree(2); // true (platform-dependent)
Atomics.isLockFree(3); // false
Atomics.isLockFree(4); // true
Atomics.isLockFree(5); // false
Atomics.isLockFree(6); // false
Atomics.isLockFree(7); // false
Atomics.isLockFree(8); // true (platform-dependent)
Specifications
| Specification |
|---|
| ECMAScript® 2027 Language Specification # sec-atomics.islockfree |