FixTask Documentation

Back to summary

import "task/atomic";

Atomic class

Atomic class allows to do atomic operations on shared arrays.

You must not mix different kinds of operations as these can use different mechanisms to achieve the atomicity (native atomic instructions or emulation using small number of mutexes selected semi-randomly based on the native pointer value). You can mix get/set/add/cas operations of the same size.

Functions

static function get32(arr: Integer[], idx: Integer): Integer
static function get64(arr: Integer[], idx: Integer): Integer, Integer
Gets the 32bit or 64bit value atomically. The 64bit version returns the value as two integer values.
static function set32(arr: Integer[], idx: Integer, value: Integer)
static function set64(arr: Integer[], idx: Integer, lo: Integer, hi: Integer)
Sets the 32bit or 64bit value atomically.
static function add32(arr: Integer[], idx: Integer, value: Integer): Integer
static function add64(arr: Integer[], idx: Integer, lo: Integer, hi: Integer): Integer, Integer
Adds the 32bit or 64bit value atomically and returns the previous value. The 64bit version returns the value as two integer values.
static function cas32(arr: Integer[], idx: Integer, expected_value: Integer, new_value: Integer): Integer
static function cas64(arr: Integer[], idx: Integer, expected_lo: Integer, expected_hi: Integer, new_lo: Integer, new_hi: Integer): Integer, Integer
Does a conditional atomic set of 32bit or 64bit value. The value is set only when the previous value is the same as expected. The previous value is returned. The 64bit version returns the value as two integer values.
static function run(arr: Integer[], idx: Integer, func, data): Dynamic
Runs the provided function while locking the index of the given array (the array can be null, in that case only the index is used for the locking and can have any value including the negative numbers). The function must not do more locking otherwise a dead-lock can occur. Returns the returned value from the function.