Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

JavaScript | Atomics.notify() Method

  • Last Updated : 02 Aug, 2021

Among the Atomic Operations, there is an inbuilt operation Atomics.notify() in JavaScript that is used to notify up some agents that are sleeping in the wait queue. The Atomics.notify() method returns a number of woken up agents. The integer typed array, index, and the count are passed as an argument to the function.
Syntax: 
 

Atomics.notify(typedArray, index, count)

Parameters: This method accept three parameters as mentioned above and described below: 
 

  • typedarray: This parameter specifies a shared integer typed array Int16Array.
  • index: This parameter specifies the position in the array, typedArray to wait on.
  • count: This parameter counts the number of sleeping agents to notify. Its default value is +Infinity.

Return value: The Atomics.notify() method returns the number of woken up agents.
Below programs illustrate the Atomics.notify() method in JavaScript:
Program 1: 
 

javascript




const sab = new SharedArrayBuffer(1024);
const int32 = new Int32Array(sab);
int32[0] = 77;
console.log(int32[0]);
console.log(Atomics.store(int32, 0, 123));
console.log(Atomics.notify(int32, 0, 1));

Output: 
 

77
123
0

Program 2: 
 

javascript




const sab = new SharedArrayBuffer(1024);
const int32 = new Int32Array(sab);
int32[0] = 77;
console.log(Atomics.load(int32, 66));
console.log(int32[0]);
console.log(Atomics.store(int32, 0, 123));
console.log(Atomics.notify(int32, 6, 1));
console.log(int32[0]);

Output: 
 

0
77
123
0
123

Exceptions: 
 

  • If the typedArray is not a shared Int32Array then the Atomics.notify( ) operation throws a TypeError.
  • If the index used as an argument to the Atomics.notify() operation is out of the bound in the typedArray then the Atomics.store( ) operation throws a RangeError.

Supported Browser:

  • Google Chrome
  • Microsoft Edge
  • Firefox

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!