Atomics - isLockFree() Method

isLockFree method is used to determine whether locks are to be used or not for atomic operations. If given size is one of TypedArray.BYTES_PER_ELEMENT property of integer TypedArray types then it returns true. TypedArray.BYTES_PER_ELEMENT represents the size in bytes of each element of an typed array.




  • size to be checked in bytes.


Returns true if operation is lock free as false.


Following is the code for implementing JavaScript Atomics −

<!DOCTYPE html>
<html lang="en">
      <meta charset="UTF-8" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      <title>Atomics Example</title>
         .result {
            font-size: 20px;
            border: 1px solid black;
   <body onLoad="operate();">
      <h1>JavaScript Atomics Properties</h1>
      <div class="result"></div>
         function operate(){
            let container = document.querySelector(".result");
            // create a SharedArrayBuffer
            var buffer = new SharedArrayBuffer(25);
            var arr = new Uint8Array(buffer);
            // Initialise element at zeroth position of array with 6
            arr[0] = 6;
            // Int8Array.BYTES_PER_ELEMENT = 1
            container.innerHTML = Atomics.isLockFree(Int8Array.BYTES_PER_ELEMENT) + '<br/>' + Atomics.isLockFree(3);


Verify the result.

Kickstart Your Career

Get certified by completing the course

Get Started