Int API:

Module shared_atomic

class shared_atomic.atomic_int. atomic_int ( value: long long , mode: unicode = 'singleprocessing' , windows_unix_compatibility: bool = False )

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

reference: readonly pointer to the integer

value: read/write value of the integer

mode: readonly ‘s’ for single process, ‘m’ for multiprocessing, on windows platform, only singleprocessing is supported

windows_unix_compatibility: readonly whether the source code should be compatible with windows x64

constructor of atomic_int :attributes

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 windows x64

get ( ) long long

getter

Returns

value

int_add_and_fetch ( n: long long ) long long

increment and fetch atomically

Parameters

n – data to add

Returns

sum of the 2 values

int_and_and_fetch ( n: long long ) long long

bitwise AND and fetch the result atomically

Parameters

n – data to AND

Returns

resulted value

int_compare_and_set ( e: typing.self_atomic_int , n: long long ) bool

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 e

  • n – value to be set

Returns

whether the contents of v and contents of e is the same

int_compare_and_set_value ( e: long long , n: long long ) long long

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 ( n: long long ) long long

fetch and increment atomically

Parameters

n – data to add

Returns

original value in v

int_fetch_and_and ( n: long long ) long long

fetch then bitwise AND atomically

Parameters

n – data to AND

Returns

the result

int_fetch_and_nand ( n: long long ) long long

fetch then bitwise NAND atomically

Parameters

n – data to NAND

Returns

the result

int_fetch_and_or ( n: long long ) long long

fetch then bitwise OR atomically

Parameters

n – data to OR

Returns

the result

int_fetch_and_sub ( n: long long ) long long

fetch and subtract atomically

Parameters

n – data to subtract

Returns

original value in v

int_fetch_and_xor ( n: long long ) long long

fetch then bitwise XOR atomically

Parameters

n – data to XOR

Returns

the result

int_get_and_set ( n: long long ) long long

get and set atomically

Parameters

n – value to set

Returns

original value

int_nand_and_fetch ( n: long long ) long long

bitwise NAND and fetch the result atomically

Parameters

n – data to NAND

Returns

resulted value

int_or_and_fetch ( n: long long ) long long

bitwise XOR and fetch the result atomically

Parameters

n – data to OR

Returns

resulted value

int_shift ( n : self_atomic_int , r : self_atomic_int )

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

Parameters
  • n – atomic_int of n

  • r – atomic_int of r

Returns

None

int_store ( n : self_atomic_int )

Store value atomically

Parameters

n – atomic_int from which value is from

Returns

None

int_sub_and_fetch ( n: long long ) long long

sub and fetch atomically

Parameters

n – data to subtract

Returns

difference of the 2 values

int_xor_and_fetch ( n: long long ) long long

bitwise XOR and fetch the result atomically

Parameters

n – data to XOR

Returns

resulted value

set ( value: long long )

setter

Parameters

value – value to set

Returns

None

property value : long long

get and set for the integer number