Atomic Operations: Atomic operations are not continuous. Multiple threads can read and write data in the memory when memory is shared. There is a loss of data if any data has changed Atomic operations ensure the data is written and accurately read by the predicted values. There is no way to change existing information until the current operation is completed and atomic operations will start.
- Atomics.add(): Adds the value provided to the current value in the array index specified. Returns the old index value.
- Atomics.and(): The value AND is computed bitwise on the index of the array specified with the value provided. Returns that index’s old value.
- Atomics.exchange(): Specifies a value at the array index specified. The old value is returned.
- Atomics.compareExchange(): Specifies the value in the specified array index if the value is the same. Old value returns.
- Atomics.isLockFree(size): Primitive optimization to determine whether locks or atomic operations are to be used. Returns true if a hardware atomic operation is carried out in the arrays of the given element size (as opposed to a lock).
- Atomics.load(): The value returns to the array index specified.
- Atomics.or(): Bitwise OR computes the value with the given value at the specified array index. Returns the old index value.
- Atomics.notify(): Notify agents waiting for the specified array index. Returns the notified number of agents.
- Atomics.sub(): Deletes a value at the array index specified. Returns the old index value.
- Atomics.store(): Save a value on the array index specified. Returns value.
- Atomics.wait(): Verifies that the specified array index still has a value and waiting or waiting times are sleeping. Returns “ok,” “not the same,” or “time-out.” If the calling agent is unable to wait, it throws an exception to an error.
- Atomics.xor(): Compute a bitwise XOR with the given value on the given array index. Returns the old index value.
5 17 17 1 1 12 1 1 True True 13 13 12 12 10 10