Int API:

Module shared_atomic.atomic_int on Linux and macOS

class shared_atomic.atomic_int.atomic_int

int provide atomic operations, the int takes 8 bytes

:attributes

value: read/write value of the integer

constructor of atomic_int

Parameters
  • value – read/write value of the integer

  • mode – ‘s’ or ‘singleprocessing’ for single process, ‘m’ or ‘multiprocessing’ for multiprocessing

  • windows_unix_compatibility – dummy parameter on unix platform, used on windows platform to indicate whether the source code should be compatible with unix platform

get()

get the contents of atomic_int atomically.

Returns

the int value

int_add_and_fetch()

increment and fetch atomically

Parameters

n – data to add

Returns

sum of the 2 values

int_and_and_fetch()

bitwise AND and fetch the result atomically

Parameters

n – data to AND

Returns

the result value

int_compare_and_set()

Compare and set atomically. This compares the contents of self with the contents of e. If equal, the operation is a read-modify-write operation that writes n into self. If they are not equal, the operation is a read and the current contents of self are written into e.

Parameters
  • e – atomic_int object

  • n – the integer value to set from

Returns

if self is equal to e return True, else return False

int_compare_and_set_value()

Compare and set atomically. This compares the contents of self with the contents of n. If equal, the operation is a read-modify-write operation that writes e into self. If they are not equal, no operation will be taken.

Parameters
  • e – The exchange value

  • n – The value to compare to

Returns

initial value

int_fetch_and_add()

fetch and increment atomically

Parameters

n – data to add

Returns

the original value

int_fetch_and_and()

fetch then bitwise AND atomically

Parameters

n – data to AND

Returns

the original value

int_fetch_and_nand()

fetch then bitwise NAND atomically

Parameters

n – data to NAND

Returns

the original value

int_fetch_and_or()

fetch then bitwise OR atomically

Parameters

n – data to OR

Returns

the original value

int_fetch_and_sub()

fetch and subtract atomically

Parameters

n – data to subtract

Returns

the original value

int_fetch_and_xor()

fetch then bitwise XOR atomically

Parameters

n – data to XOR

Returns

the original value

int_get_and_set()

get and set contents of atomic_int atomically.

Parameters

n – the integer value to set from

Returns

the original int value

int_nand_and_fetch()

bitwise NAND and fetch the result atomically

Parameters

n – data to NAND

Returns

the result value

int_or_and_fetch()

bitwise XOR and fetch the result atomically

Parameters

n – data to OR

Returns

the result value

int_shift()

value exchange between 3 atomic_ints in 2 groups atomically, store n in self after store self in r.

Parameters
  • n – the atomic_int n

  • r – the atomic_int r

Returns

None

int_store()

Store value atomically.

Parameters

n – the atomic_int to set from

Returns

None

int_sub_and_fetch()

sub and fetch atomically

Parameters

n – data to subtract

Returns

difference of the 2 values

int_xor_and_fetch()

bitwise XOR and fetch the result atomically

Parameters

n – data to XOR

Returns

the result value

set()

set the contents of atomic_int atomically.

Parameters

value – the integer value to set from

Returns

None

shared_atomic.atomic_int.int_add_and_fetch()

increment and fetch atomically

Parameters
  • integer – the atomic_int

  • n – the integer value

Returns

sum of the 2 values

shared_atomic.atomic_int.int_and_and_fetch()

Bitwise AND and fetch atomically

Parameters
  • integer – the atomic_int

  • n – data to AND

Returns

the result value

shared_atomic.atomic_int.int_compare_and_set()

Compare and set atomically. This compares the contents of integer with the contents of e. If equal, the operation is a read-modify-write operation that writes n into integer. If they are not equal, the operation is a read and the current contents of integer are written into e.

Parameters
  • integer – atomic_int object

  • e – atomic_int object

  • n – the integer value to set from

Returns

if integer is equal to e return True, else return False

shared_atomic.atomic_int.int_compare_and_set_value()

Compare and swap atomically, This compares the contents of atomic_int integer with the contents of n. If equal, the operation is a read-modify-write operation that writes e into integer. If they are not equal, No operation is performed.

Parameters
  • integer – the atomic_int

  • e – the integer value

  • n – the integer value

Returns

the initial value

shared_atomic.atomic_int.int_fetch_and_add()

increment and fetch atomically

Parameters
  • integer – the atomic_int

  • n – data to add

Returns

the initial value

shared_atomic.atomic_int.int_fetch_and_and()

fetch then bitwise AND atomically

Parameters
  • integer – the atomic_int

  • n – data to AND

Returns

the initial value

shared_atomic.atomic_int.int_fetch_and_nand()

fetch then bitwise NAND atomically

Parameters
  • integer – the atomic_int

  • n – data to NAND

Returns

the initial value

shared_atomic.atomic_int.int_fetch_and_or()

fetch then bitwise OR atomically

Parameters
  • integer – the atomic_int

  • n – data to OR

Returns

the initial value

shared_atomic.atomic_int.int_fetch_and_sub()

subtract and fetch atomically

Parameters
  • integer – the atomic_int

  • n – data to subtract

Returns

the initial value

shared_atomic.atomic_int.int_fetch_and_xor()

fetch then bitwise XOR atomically

Parameters
  • integer – the atomic_int

  • n – data to XOR

Returns

the initial value

shared_atomic.atomic_int.int_get()

get the contents of atomic_int atomically.

Parameters

integer – the atomic_int to get

Returns

the int value

shared_atomic.atomic_int.int_get_and_set()

get and set contents of atomic_int atomically.

Parameters
  • integer – the atomic_int

  • n – the integer value to set from

Returns

the original int value

shared_atomic.atomic_int.int_nand_and_fetch()

Bitwise NAND and fetch atomically

Parameters
  • integer – the atomic_int

  • n – data to NAND

Returns

the result value

shared_atomic.atomic_int.int_or_and_fetch()

Bitwise OR and fetch atomically

Parameters
  • integer – the atomic_int

  • n – data to OR

Returns

the result value

shared_atomic.atomic_int.int_set()

set the contents of atomic_int atomically.

Parameters
  • integer – the atomic_int to set

  • n – the integer value to set from

Returns

None

shared_atomic.atomic_int.int_shift()

value exchange between 3 atomic_ints in 2 groups atomically, store n in integer after store integer in r.

Parameters
  • integer – the atomic_int integer

  • n – the atomic_int n

  • r – the atomic_int r

Returns

None

shared_atomic.atomic_int.int_store()

Store value atomically.

Parameters
  • integer – the atomic_int to set

  • n – the atomic_int to set from

Returns

None

shared_atomic.atomic_int.int_sub_and_fetch()

sub and fetch atomically

Parameters
  • integer – the atomic_int

  • n – the integer value

Returns

sum of the 2 values

shared_atomic.atomic_int.int_xor_and_fetch()

Bitwise XOR and fetch atomically

Parameters
  • integer – the atomic_int

  • n – data to XOR

Returns

the result value

On Microsoft Windows

class shared_atomic.atomic_int.atomic_int

int provide atomic operations, the int takes 8 bytes :attributes

value: used to get and set the value atomically

constructor of atomic_int

Parameters
  • value – read/write value of the integer

  • mode – ‘s’ or ‘singleprocessing’ for single process, ‘m’ or ‘multiprocessing’ for multiprocessing

  • windows_unix_compatibility – whether the source code should be compatible with unix

get()

get the integer value from the atomic_integer :return: value

int_add_and_fetch()

increment and fetch atomically

Parameters

n – data to add

Returns

sum of the 2 values

int_bittest_and_reset()

Tests the specified bit and set it to 0 atomically

Parameters

offset – offset in the binary presenation of the 64bit integer

Returns

the initial value(True or False) of specified bit

int_bittest_and_set()

Tests the specified bit and set it to 1 atomically

Parameters

offset – offset in the binary presenation of the 64bit integer

Returns

the initial value(True or False) of specified bit

int_compare_and_set_value()

Compare and set atomically. This compares the contents of self with the contents of n. If equal, the operation is a read-modify-write operation that writes n into self. If they are not equal, no operation will be taken.

Parameters
  • e – the value to set from

  • n – the value to compare to

Returns

None

int_fetch_and_add()

fetch and increment atomically

Parameters

n – data to add

Returns

original value

int_fetch_and_and()

fetch then bitwise AND atomically

Parameters

n – data to AND

Returns

original value

int_fetch_and_or()

fetch then bitwise OR atomically

Parameters

n – data to OR

Returns

original value

int_fetch_and_sub()

fetch and substract atomically

Parameters

n – data to sub

Returns

original value

int_fetch_and_xor()

fetch then bitwise XOR atomically

Parameters

n – data to XOR

Returns

original value

int_get_and_set()

get and set atomically

Parameters

n – value to set

Returns

None

int_sub_and_fetch()

sub and fetch atomically

Parameters

n – data to add

Returns

difference of the 2 values

set()

set the integer value from the atomic_integer

Parameters

value – value to set

Returns

None

shared_atomic.atomic_int.int_add_and_fetch()

increment and fetch atomically

Parameters
  • reference – the reference used in subprocess

  • n – the integer value

Returns

sum of the 2 values

shared_atomic.atomic_int.int_bittest_and_reset()

Tests the specified bit and set it to 0 atomically

Parameters
  • reference – the reference used in subprocess

  • offset – offset in the binary presenation of the 64bit integer

Returns

the initial value(True or False) of specified bit

shared_atomic.atomic_int.int_bittest_and_set()

fetch then bitwise NAND atomically

Parameters
  • reference – the reference used in subprocess

  • offset – offset in the binary presenation of the 64bit integer

Returns

the initial value(True or False) of specified bit

shared_atomic.atomic_int.int_compare_and_set_value()

Compare and swap atomically, This compares the contents of subprocess reference with the contents of n. If equal, the operation is a read-modify-write operation that writes e into self. If they are not equal, No operation is performed.

Parameters
  • reference – the reference used in subprocess

  • e – the integer value

  • n – the integer value

Returns

the initial value

shared_atomic.atomic_int.int_fetch_and_add()

increment and fetch atomically

Parameters
  • reference – the reference used in subprocess

  • n – data to add

Returns

the initial value

shared_atomic.atomic_int.int_fetch_and_and()

fetch then bitwise AND atomically

Parameters
  • reference – the reference used in subprocess

  • n – data to AND

Returns

the initial value

shared_atomic.atomic_int.int_fetch_and_or()

fetch then bitwise OR atomically

Parameters
  • reference – the reference used in subprocess

  • n – data to OR

Returns

the initial value

shared_atomic.atomic_int.int_fetch_and_sub()

subtract and fetch atomically

Parameters
  • reference – the reference used in subprocess

  • n – data to subtract

Returns

the initial value

shared_atomic.atomic_int.int_fetch_and_xor()

fetch then bitwise XOR atomically

Parameters
  • reference – the reference used in subprocess

  • n – data to XOR

Returns

the initial value

shared_atomic.atomic_int.int_get()

get the contents of subprocess reference atomically.

Parameters

reference – the reference used in subprocess

Returns

the int value

shared_atomic.atomic_int.int_get_and_set()

get and set contents of subprocess reference atomically.

Parameters
  • reference – the reference used in subprocess

  • n – the integer value to set from

Returns

the original int value

shared_atomic.atomic_int.int_set()

set the contents of subprocess reference atomically.

Parameters
  • reference – the reference used in subprocess

  • n – the integer value to set from

Returns

None

shared_atomic.atomic_int.int_sub_and_fetch()

sub and fetch atomically

Parameters
  • reference – the reference used in subprocess

  • n – the integer value

Returns

sum of the 2 values