Shared Memory API:

Module shared_atomic.atomic_shared_memory on Linux and macOS

class shared_atomic.atomic_shared_memory.atomic_shared_memory

Shared memory provide atomic operations

:attributes

standalone: readonly pointer to the start of the shared memory

dealloc_async: public whether the deallocation run in asynchronized fashion, useless on Microsoft Windows platform.

f: readonly file property to access the standalone file if standalone shared memory is specified

buf: memoryview interface

constructor to initialize the shared memory

Parameters
  • initial – initial value in the shared memory.

  • mode – the mode in which the list will be shared. ‘singleprocessing’ or ‘s’ for single process, ‘multiprocessing’ or ‘m’ for multiprocessing, on windows platform, only singleprocessing is supported, setting it to ‘m’ or ‘multiprocessing’ will be ignored.

  • length – the expected length after padding/trimming for the input value, if not specified, no padding or trimming performed, use original value.

  • paddingdirection – if not specified, no padding is performed, if specified, right, or left side the padding bytes would be added, use ‘right’ or ‘r’ to specify right side, use ‘left’ or ‘l’ to specify the left side.

  • paddingbytes – bytes to pad to the original bytes, by default b’\0’ can be multiple bytes like b’ab’, will be padded to the original bytes in circulation until the expected length is reached.

  • trimming_direction – if initial bytes are longer, on which side the bytes will be trimmed. By default, on the right side, use ‘right’ or ‘r’ to specify right side, use ‘left’ or ‘l’ to specify the left side.

  • windows_unix_compatibility – dummy parameter on linux and macOS, used on windows to indicate whether needs to be compatible with linux and macOS.

  • source – if the data source is file, use 'f', if the data source is the initial parameter, let it remain default 'p'.

  • previous_shared_memory_path – if the data source is file, set the path of the file

  • remove_previous_file – if the loaded data file should be removed after initilization, default to False

  • standalone – if the shared memory should be left valid, not cleansed after the object destroyed.

  • dealloc_async – whether the deallocation run in asynchronized fashion, useless on Microsoft Windows platform.

file_sync()

sync to the file system for standalone shared memory

Parameters
  • async – whether the file writes are synchronized on unix platform, True for asynchronize, False for synchronize. Useless on windows platform, which is always synchronized

  • start – starting offset of the shared memory to sync.

  • length – length of bytes in the shared memory to sync.

Returns

0 if sucessful, raises exception otherwise.

memdump()

Dump the data at specific offset given specific length using memcpy, it’s NOT atomic method the data can be any length.

Parameters
  • file_path – file path the dump of the shared memory is written to

  • start – offset in the shared memory from which the data is dumped

  • length – the length of data in bytes to dump

Returns

number of bytes written to disk

offset_add_and_fetch()

increment and fetch atomically

Parameters
  • value – data to add

  • offset – the offset inside the shared memory starting from 0 you need to add,

Returns

sum of the 2 values

offset_add_and_fetches()

increment and fetch atomically at specific offsets given specific lengths

Parameters
  • values – rows of bytes to add to, rows will be right trimmed according to lengths array

  • offsets – the array of offsets inside the shared memory starting from 0

  • lengths – the array of lengths of bytes should be retrieved

  • parallelism – the wanted degree of parallelism

Returns

rows of sum of the two bytes representation of values and shared memory bytes, the width is the max given length, rows of other lengths are padded by ‘\0’.

offset_and_and_fetch()

bitwise AND and fetch the result atomically

Parameters
  • value – data to AND

  • offset – the offset inside the shared memory starting from 0 you need to AND with,

Returns

the result value

offset_and_and_fetches()

Bitwise AND and fetch atomically at specific offsets given specific lengths

Parameters
  • values – rows of bytes to AND, rows will be right trimmed according to lengths array

  • offsets – the array of offsets inside the shared memory starting from 0

  • lengths – the array of lengths of bytes should be retrieved

  • parallelism – the wanted degree of parallelism

Returns

rows of differences of the two bytes representation of values and shared memory bytes, the width is the max given length, rows of other lengths are padded by ‘\0’.

offset_compare_and_set()

Compare and set atomically. This compares the contents of shared_memory2 at offset2 with the contents of self at offset. If equal, the operation is a read-modify-write operation that writes bytes parameter value into self. If they are not equal, the operation is a read and the current contents of self are written into shared_memory2.

Parameters
  • shared_memory2 – the other shared memory from which the data is from

  • value – the value to write to the shared memory,

  • offset – the offset inside the shared memory starting from 0 you need to set,

  • offset2 – the offset2 inside the shared memory 2 starting from 0 you need to get,

Returns

whether the contents of self and contents of shared_memory2 is the same

offset_compare_and_set_value()

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

Parameters
  • i – exchange value

  • n – The value to be compared with

  • offset – the offset inside the shared memory starting from 0 you need to set,

Returns

the original value at offset

offset_compare_and_set_values()

Atomically get and set the bytes at specific offsets given specific lengths

Parameters
  • ies – rows of bytes to set from, each row will be right trimmed according to the lengths array

  • ns – rows of bytes to be compared with, each row will be right trimmed according to the lengths array

  • offsets – the array of offsets inside the shared memory starting from 0

  • lengths – the array of lengths of bytes should be retrieved

  • parallelism – the wanted degree of parallelism

Returns

rows of original bytes at specific offsets, the width is the max given length, rows of other lengths are padded by ‘\0’.

offset_compare_and_sets()

Compare and set atomically. This compares the contents of shared_memory2 at offset2 with the contents of self at offset. If equal, the operation is a read-modify-write operation that writes bytes parameter value into self. If they are not equal, the operation is a read and the current contents of self are written into shared_memory2.

Parameters
  • other_memories – the other shared memorys from which the data is from

  • values – the value to write to the shared memory,

  • offsets – the offset inside the shared memory starting from 0 you need to set,

  • offsets2 – the offset2 inside the shared memory 2 starting from 0 you need to get,

  • lengths – the length to compare and set,

Returns

whether the contents of self and contents of shared_memory2 is the same

offset_compare_with_other_type_and_set()

Compare and set atomically. This compares the contents of another atomic_object with the contents of self at offset. If equal, the operation is a read-modify-write operation that writes bytes parameter value into self. If they are not equal, the operation is a read and the current contents of self are written into object2.

Parameters
  • object2 – the other atomic object from which the data is compared with

  • offset – the offset inside the shared memory starting from 0 you need to compare and set,

  • value – value to be set

Returns

whether the contents of self and contents of object2 is the same

offset_fetch_and_add()

fetch and increment atomically

Parameters
  • value – data to add

  • offset – the offset inside the shared memory starting from 0 you need to add to,

Returns

original value

offset_fetch_and_adds()

fetch and increment atomically at specific offsets given specific lengths

Parameters
  • values – rows of bytes to add to, rows will be right trimmed according to lengths array

  • offsets – the array of offsets inside the shared memory starting from 0

  • lengths – the array of lengths of bytes should be retrieved

  • parallelism – the wanted degree of parallelism

Returns

rows of original bytes representation of shared memory, the width is the max given length, rows of other lengths are padded by ‘\0’.

offset_fetch_and_and()

fetch then bitwise AND atomically

Parameters
  • value – value to AND to

  • offset – the offset inside the shared memory starting from 0 you need to AND to,

Returns

original value

offset_fetch_and_ands()

fetch and AND atomically at specific offsets given specific lengths

Parameters
  • values – rows of bytes to and, rows will be right trimmed according to lengths array

  • offsets – the array of offsets inside the shared memory starting from 0

  • lengths – the array of lengths of bytes should be retrieved

  • parallelism – the wanted degree of parallelism

Returns

rows of original bytes representation of shared memory, the width is the max given length, rows of other lengths are padded by ‘\0’.

offset_fetch_and_nand()

fetch then bitwise NAND atomically

Parameters
  • value – value to NAND with

  • offset – the offset inside the shared memory starting from 0 you need to NAND with,

Returns

original value

offset_fetch_and_nands()

fetch and NAND atomically at specific offsets given specific lengths

Parameters
  • values – rows of bytes to xor, rows will be right trimmed according to lengths array

  • offsets – the array of offsets inside the shared memory starting from 0

  • lengths – the array of lengths of bytes should be retrieved

  • parallelism – the wanted degree of parallelism

Returns

rows of original bytes representation of shared memory, the width is the max given length, rows of other lengths are padded by ‘\0’.

offset_fetch_and_or()

fetch then bitwise OR atomically

Parameters
  • value – value to OR with

  • offset – the offset inside the shared memory starting from 0 you need to OR with,

Returns

original value

offset_fetch_and_ors()

fetch and OR atomically at specific offsets given specific lengths

Parameters
  • values – rows of bytes to or, rows will be right trimmed according to lengths array

  • offsets – the array of offsets inside the shared memory starting from 0

  • lengths – the array of lengths of bytes should be retrieved

  • parallelism – the wanted degree of parallelism

Returns

rows of original bytes representation of shared memory, the width is the max given length, rows of other lengths are padded by ‘\0’.

offset_fetch_and_sub()

fetch and substract atomically

Parameters
  • value – data to add

  • offset – the offset inside the shared memory starting from 0 you need to substract from,

Returns

original value

offset_fetch_and_subs()

fetch and substract atomically at specific offsets given specific lengths

Parameters
  • values – rows of bytes to substract, rows will be right trimmed according to lengths array

  • offsets – the array of offsets inside the shared memory starting from 0

  • lengths – the array of lengths of bytes should be retrieved

  • parallelism – the wanted degree of parallelism

Returns

rows of original bytes representation of shared memory, the width is the max given length, rows of other lengths are padded by ‘\0’.

offset_fetch_and_xor()

fetch then bitwise XOR atomically

Parameters
  • value – value to XOR with

  • offset – the offset inside the shared memory starting from 0 you need to XOR with,

Returns

original value

offset_fetch_and_xors()

fetch and XOR atomically at specific offsets given specific lengths

Parameters
  • values – rows of bytes to xor, rows will be right trimmed according to lengths array

  • offsets – the array of offsets inside the shared memory starting from 0

  • lengths – the array of lengths of bytes should be retrieved

  • parallelism – the wanted degree of parallelism

Returns

rows of original bytes representation of shared memory, the width is the max given length, rows of other lengths are padded by ‘\0’.

offset_get()

Atomically get the bytes at specific offset given specific length

Parameters
  • offset – the offset inside the shared memory starting from 0, including the operation length

  • length – the length of bytes should be retrieved

Returns

bytes at specific offset.

offset_get_and_set()

Atomically set the bytes at specific offset given specific length

Parameters
  • value – new value in bytes

  • offset – the offset inside the shared memory starting from 0, including the operation length

Returns

bytes at specific offset previously.

offset_get_and_sets()

Atomically get the bytes at specific offsets given specific lengths

Parameters
  • values – rows of bytes at specific offsets, rows will be right trimmed according to lengths array

  • offsets – the array of offsets inside the shared memory starting from 0

  • lengths – the array of lengths of bytes should be retrieved

  • parallelism – the wanted degree of parallelism

Returns

rows of bytes at specific offsets, the width is the max given length, rows of other lengths are padded by ‘\0’.

offset_gets()

Atomically get the bytes at specific offsets given specific lengths

Parameters
  • offsets – the array of offsets inside the shared memory starting from 0

  • lengths – the array of lengths of bytes should be retrieved

  • parallelism – the wanted degree of parallelism

Returns

rows of bytes at specific offsets, the width is the max given length, rows of other lengths are padded by ‘\0’.

offset_memmove()

Set or read the data at specific offset given specific length using memcpy, it’s NOT atomic method the data can be any length incase you don’t need atomicity or should use other lengths

Parameters
  • mv – the data source as memoryview to read from or write to

  • offset – offset in the shared memory to read from or write to

  • io_flags – ‘i’ to write from the mv to the shared memory, ‘o’ to read from the shared memory to the mv

Returns

None

offset_nand_and_fetch()

bitwise NAND and fetch the result atomically

Parameters
  • value – data to NAND

  • offset – the offset inside the shared memory starting from 0 you need to NAND with,

Returns

the result value

offset_nand_and_fetches()

Bitwise NAND and fetch atomically at specific offsets given specific lengths

Parameters
  • values – rows of bytes to NAND, rows will be right trimmed according to lengths array

  • offsets – the array of offsets inside the shared memory starting from 0

  • lengths – the array of lengths of bytes should be retrieved

  • parallelism – the wanted degree of parallelism

Returns

rows of differences of the two bytes representation of values and shared memory bytes, the width is the max given length, rows of other lengths are padded by ‘\0’.

offset_or_and_fetch()

bitwise OR and fetch the result atomically

Parameters
  • value – data to OR

  • offset – the offset inside the shared memory starting from 0 you need to OR with,

Returns

the result value

offset_or_and_fetches()

Bitwise OR and fetch atomically at specific offsets given specific lengths

Parameters
  • values – rows of bytes to OR, rows will be right trimmed according to lengths array

  • offsets – the array of offsets inside the shared memory starting from 0

  • lengths – the array of lengths of bytes should be retrieved

  • parallelism – the wanted degree of parallelism

Returns

rows of differences of the two bytes representation of values and shared memory bytes, the width is the max given length, rows of other lengths are padded by ‘\0’.

offset_store()

Atomically set the data at specific offset given specific length

Parameters
  • shared_memory2 – the other shared memory from which the data is from

  • offset – the offset inside the shared memory starting from 0 you need to set,

  • offset2 – the offset inside the shared memory from the data you want,

  • length – the length of bytes should be set in the shared memory and

get the data from the shared memory 2, only 1,2,4 and 8 are supported :return: None

offset_store_from_other_types()

Atomically set the data at specific offset given specific length, if object2 is in variable length, and object2 is changing the size at the same time, the method will not be atomic, otherwise, the operation is atomic.

Parameters
  • object2 – the other atomic object from which the data is from

  • offset – the offset inside the shared memory starting from 0 you need to set

Returns

None

offset_sub_and_fetch()

increment and fetch atomically

Parameters
  • value – data to add

  • offset – the offset inside the shared memory starting from 0 you need to add,

Returns

sum of the 2 values

offset_sub_and_fetches()

substract and fetch atomically at specific offsets given specific lengths

Parameters
  • values – rows of bytes to substract, rows will be right trimmed according to lengths array

  • offsets – the array of offsets inside the shared memory starting from 0

  • lengths – the array of lengths of bytes should be retrieved

  • parallelism – the wanted degree of parallelism

Returns

rows of differences of the two bytes representation of values and shared memory bytes, the width is the max given length, rows of other lengths are padded by ‘\0’.

offset_xor_and_fetch()

bitwise XOR and fetch the result atomically

Parameters
  • value – data to XOR

  • offset – the offset inside the shared memory starting from 0 you need to XOR with,

Returns

the result value

offset_xor_and_fetches()

Bitwise XOR and fetch atomically at specific offsets given specific lengths

Parameters
  • values – rows of bytes to XOR, rows will be right trimmed according to lengths array

  • offsets – the array of offsets inside the shared memory starting from 0

  • lengths – the array of lengths of bytes should be retrieved

  • parallelism – the wanted degree of parallelism

Returns

rows of differences of the two bytes representation of values and shared memory bytes, the width is the max given length, rows of other lengths are padded by ‘\0’.

shared_atomic.atomic_shared_memory.shared_memory_offset_add_and_fetch()

increment and fetch atomically

Parameters
  • value – data to add

  • offset – the offset inside the shared memory starting from 0 you need to add,

Returns

sum of the 2 values

shared_atomic.atomic_shared_memory.shared_memory_offset_and_and_fetch()

bitwise AND and fetch the result atomically

Parameters
  • value – data to AND

  • offset – the offset inside the shared memory starting from 0 you need to AND with,

Returns

the result value

shared_atomic.atomic_shared_memory.shared_memory_offset_compare_and_set()

Compare and set atomically. This compares the contents of shared_memory2 at offset2 with the contents of memory at offset. If equal, the operation is a read-modify-write operation that writes bytes parameter value into self. If they are not equal, the operation is a read and the current contents of memory are written into shared_memory2.

Parameters
  • memory – target shared memory.

  • shared_memory2 – the other shared memory from which the data is from

  • value – the value to write to the shared memory,

  • offset – the offset inside the shared memory starting from 0 you need to set,

  • offset2 – the offset2 inside the shared memory 2 starting from 0 you need to get,

Returns

whether the contents of memory and contents of shared_memory2 is the same

shared_atomic.atomic_shared_memory.shared_memory_offset_compare_and_set_value()

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

Parameters
  • memory – target shared memory.

  • i – exchange value

  • n – The value to be compared with

  • offset – the offset inside the shared memory starting from 0 you need to set,

Returns

the original value at offset

shared_atomic.atomic_shared_memory.shared_memory_offset_compare_with_other_type_and_set()

Compare and set atomically. This compares the contents of another atomic_object with the contents of memory at offset. If equal, the operation is a read-modify-write operation that writes bytes parameter value into memory. If they are not equal, the operation is a read and the current contents of self are written into object2.

Parameters
  • memory – target shared memory.

  • object2 – the other atomic object from which the data is compared with

  • offset – the offset inside the shared memory starting from 0 you need to compare and set,

  • value – value to be set

Returns

whether the contents of memory and contents of object2 is the same

shared_atomic.atomic_shared_memory.shared_memory_offset_fetch_and_add()

fetch and increment atomically

Parameters
  • memory – target shared memory.

  • value – data to add

  • offset – the offset inside the shared memory starting from 0 you need to add to,

Returns

original value

shared_atomic.atomic_shared_memory.shared_memory_offset_fetch_and_and()

fetch then bitwise AND atomically

Parameters
  • memory – target shared memory.

  • value – value to AND to

  • offset – the offset inside the shared memory starting from 0 you need to AND to,

Returns

original value

shared_atomic.atomic_shared_memory.shared_memory_offset_fetch_and_nand()

fetch then bitwise NAND atomically

Parameters
  • memory – target shared memory.

  • value – value to NAND with

  • offset – the offset inside the shared memory starting from 0 you need to NAND with,

Returns

original value

shared_atomic.atomic_shared_memory.shared_memory_offset_fetch_and_or()

fetch then bitwise OR atomically

Parameters
  • memory – target shared memory.

  • value – value to OR with

  • offset – the offset inside the shared memory starting from 0 you need to OR with,

Returns

original value

shared_atomic.atomic_shared_memory.shared_memory_offset_fetch_and_sub()

fetch and substract atomically

Parameters
  • memory – target shared memory.

  • value – data to sub

  • offset – the offset inside the shared memory starting from 0 you need to substract from,

Returns

original value

shared_atomic.atomic_shared_memory.shared_memory_offset_fetch_and_xor()

fetch then bitwise XOR atomically

Parameters
  • memory – target shared memory.

  • value – value to XOR with

  • offset – the offset inside the shared memory starting from 0 you need to XOR with,

Returns

original value

shared_atomic.atomic_shared_memory.shared_memory_offset_get()

Atomically get the bytes at specific offset given specific length

Parameters
  • memory – target shared memory.

  • offset – the offset inside the shared memory starting from 0

  • length – the length of bytes should be retrieved

Returns

bytes at specific offset.

shared_atomic.atomic_shared_memory.shared_memory_offset_get_and_set()

Atomically set the bytes at specific offset given specific length

Parameters
  • memory – target shared memory.

  • value – new value in bytes

  • offset – the offset inside the shared memory starting from 0, including the operation length

Returns

bytes at specific offset previously.

shared_atomic.atomic_shared_memory.shared_memory_offset_nand_and_fetch()

bitwise NAND and fetch the result atomically

Parameters
  • memory – target shared memory.

  • value – data to NAND

  • offset – the offset inside the shared memory starting from 0 you need to NAND with,

Returns

the result value

shared_atomic.atomic_shared_memory.shared_memory_offset_or_and_fetch()

bitwise OR and fetch the result atomically

Parameters
  • memory – target shared memory.

  • value – data to OR

  • offset – the offset inside the shared memory starting from 0 you need to OR with,

Returns

the result value

shared_atomic.atomic_shared_memory.shared_memory_offset_store()

Atomically set the data at specific offset given specific length

Parameters
  • memory – target shared memory.

  • shared_memory2 – the other shared memory from which the data is from

  • offset – the offset inside the shared memory starting from 0 you need to set,

  • offset2 – the offset inside the shared memory from the data you want,

  • length – the length of bytes should be set in the shared memory and get the data from the shared memory 2, only 1,2,4 and 8 are supported

Returns

None

shared_atomic.atomic_shared_memory.shared_memory_offset_store_from_other_types()

Atomically set the data at specific offset given specific length, if object2 is in variable length, and object2 is changing the size at the same time, the method will not be atomic, otherwise, the operation is atomic.

Parameters
  • memory – target shared memory.

  • object2 – the other atomic object from which the data is from

  • offset – the offset inside the shared memory starting from 0 you need to set

Returns

None

shared_atomic.atomic_shared_memory.shared_memory_offset_sub_and_fetch()

increment and fetch atomically

Parameters
  • memory – target shared memory.

  • value – data to sub

  • offset – the offset inside the shared memory starting from 0 you need to add,

Returns

sum of the 2 values

shared_atomic.atomic_shared_memory.shared_memory_offset_xor_and_fetch()

bitwise XOR and fetch the result atomically

Parameters
  • memory – target shared memory.

  • value – data to XOR

  • offset – the offset inside the shared memory starting from 0 you need to XOR with,

Returns

the result value

On Microsoft Windows

class shared_atomic.atomic_shared_memory.atomic_shared_memory

Shared memory provide atomic operations

:attributes

standalone: readonly pointer to the start of the shared memory

dealloc_async: public whether the deallocation run in asynchronized fashion, useless on Microsoft Windows platform.

f: readonly file property to access the standalone file if standalone shared memory is specified

buf: memoryview interface

constructor to initialize the shared memory

Parameters
  • initial – initial value in the shared memory, if you decide to use this parameter as data source of the shared memory.

  • mode – the mode in which the list will be shared. ‘singleprocessing’ or ‘s’ for single process, ‘multiprocessing’ or ‘m’ for multiprocessing, on windows platform, only singleprocessing is supported, setting it to ‘m’ or ‘multiprocessing’ will be ignored.

  • length – the expected length after padding/trimming for the input value, if not specified, no padding or trimming performed, use original value.

  • paddingdirection – if not specified, no padding is performed, if specified, right, or left side the padding bytes would be added, use ‘right’ or ‘r’ to specify right side, use ‘left’ or ‘l’ to specify the left side.

  • paddingbytes – bytes to pad to the original bytes, by default b’\0’ can be multiple bytes like b’ab’, will be padded to the original bytes in circulation until the expected length is reached.

  • trimming_direction – if initial bytes are longer, on which side the bytes will be trimmed. By default, on the right side, use ‘right’ or ‘r’ to specify right side, use ‘left’ or ‘l’ to specify the left side.

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

  • source – if the data source is file, use ‘f’, if the data source is the initial parameter, let it remain default ‘p’.

  • previous_shared_memory_path – if the data source is file, set the path of the file

  • remove_previous_file – if the loaded data file should be removed after initilization, default to False

  • standalone – if the shared memory should be left at the file system backend, after the shared memory deallocated.

  • dealloc_async – whether the deallocation run in asynchronized fashion, useless on Microsoft Windows platform.

file_sync()

sync to the file system for standalone shared memory

Parameters
  • async – whether the file writes are synchronized on unix platform, True for asynchronize, False for synchronize. Useless on windows platform, which is always synchronized

  • start – starting offset of the shared memory to sync.

  • length – length of bytes in the shared memory to sync.

Returns

0 if sucessful, raises exception otherwise.

memdump()

Dump the data at specific offset given specific length using memcpy, it’s NOT atomic method the data can be any length.

Parameters
  • file_path – file path the dump of the shared memory is written to

  • start – offset in the shared memory from which the data is dumped

  • length – the length of data in bytes to dump

Returns

number of bytes written to disk

offset_add_and_fetch()

increment and fetch atomically

Parameters
  • value – data to add

  • offset – the offset inside the shared memory starting from 0 you need to add to,

Returns

sum of the 2 values

offset_add_and_fetches()

increment and fetch atomically at specific offsets given specific lengths

Parameters
  • values – rows of bytes to add to, rows will be right trimmed according to lengths array

  • offsets – the array of offsets inside the shared memory starting from 0

  • lengths – the array of lengths of bytes should be retrieved

  • parallelism – the wanted degree of parallelism

Returns

rows of sum of the two bytes representation of values and shared memory bytes, the width is the max given length, rows of other lengths are padded by ‘\0’.

offset_bittest_and_reset()

test and reset the bit at offset atomically

Parameters

left_offset – the offset inside the shared memory starting from 0 you need to reset,

Returns

original value

offset_bittest_and_resets()

test and reset the bit at offset atomically at specific offsets given specific lengths

Parameters
  • left_offsets – the array of bit-wise offsets inside the shared memory starting from 0

  • parallelism – the wanted degree of parallelism

Returns

rows of original bit in shared memory’.

offset_bittest_and_set()

test and set the bit at offset atomically

Parameters

left_offset – the offset inside the shared memory starting from 0 you need to set,

Returns

original value

offset_bittest_and_sets()

test and set the bit at offset atomically at specific offsets given specific lengths

Parameters
  • left_offsets – the array of bit-wise offsets inside the shared memory starting from 0

  • parallelism – the wanted degree of parallelism

Returns

rows of original bit in shared memory’.

offset_compare_and_set_value()

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

Parameters
  • i – exchange value

  • n – The value to be compared with

  • offset – the offset inside the shared memory starting from 0 you need to set,

Returns

the original value at offset

offset_compare_and_set_values()

Atomically get and set the bytes at specific offsets given specific lengths

Parameters
  • ies – rows of bytes to set from, each row will be right trimmed according to the lengths array

  • ns – rows of bytes to be compared with, each row will be right trimmed according to the lengths array

  • offsets – the array of offsets inside the shared memory starting from 0

  • lengths – the array of lengths of bytes should be retrieved

  • parallelism – the wanted degree of parallelism

Returns

rows of original bytes at specific offsets, the width is the max given length, rows of other lengths are padded by ‘\0’.

offset_fetch_and_add()

fetch and increment atomically

Parameters
  • value – data to add

  • offset – the offset inside the shared memory starting from 0 you need to add to,

Returns

original value

offset_fetch_and_adds()

fetch and increment atomically at specific offsets given specific lengths

Parameters
  • values – rows of bytes to add to, rows will be right trimmed according to lengths array

  • offsets – the array of offsets inside the shared memory starting from 0

  • lengths – the array of lengths of bytes should be retrieved

  • parallelism – the wanted degree of parallelism

Returns

rows of original bytes representation of shared memory, the width is the max given length, rows of other lengths are padded by ‘\0’.

offset_fetch_and_and()

fetch then bitwise AND atomically

Parameters
  • value – value to AND to

  • offset – the offset inside the shared memory starting from 0 you need to AND to,

Returns

original value

offset_fetch_and_ands()

fetch and and atomically at specific offsets given specific lengths

Parameters
  • values – rows of bytes to and, rows will be right trimmed according to lengths array

  • offsets – the array of offsets inside the shared memory starting from 0

  • lengths – the array of lengths of bytes should be retrieved

  • parallelism – the wanted degree of parallelism

Returns

rows of original bytes representation of shared memory, the width is the max given length, rows of other lengths are padded by ‘\0’.

offset_fetch_and_or()

fetch then bitwise OR atomically

Parameters
  • value – value to OR with

  • offset – the offset inside the shared memory starting from 0 you need to OR with,

Returns

original value

offset_fetch_and_ors()

fetch and or atomically at specific offsets given specific lengths

Parameters
  • values – rows of bytes to or, rows will be right trimmed according to lengths array

  • offsets – the array of offsets inside the shared memory starting from 0

  • lengths – the array of lengths of bytes should be retrieved

  • parallelism – the wanted degree of parallelism

Returns

rows of original bytes representation of shared memory, the width is the max given length, rows of other lengths are padded by ‘\0’.

offset_fetch_and_sub()

fetch and substract atomically

Parameters
  • value – data to substract

  • offset – the offset inside the shared memory starting from 0 you need to substract from,

Returns

original value

offset_fetch_and_subs()

fetch and substract atomically at specific offsets given specific lengths

Parameters
  • values – rows of bytes to substract, rows will be right trimmed according to lengths array

  • offsets – the array of offsets inside the shared memory starting from 0

  • lengths – the array of lengths of bytes should be retrieved

  • parallelism – the wanted degree of parallelism

Returns

rows of original bytes representation of shared memory, the width is the max given length, rows of other lengths are padded by ‘\0’.

offset_fetch_and_xor()

fetch then bitwise XOR atomically

Parameters
  • value – value to XOR with

  • offset – the offset inside the shared memory starting from 0 you need to XOR with,

Returns

original value

offset_fetch_and_xors()

fetch and xor atomically at specific offsets given specific lengths

Parameters
  • values – rows of bytes to xor, rows will be right trimmed according to lengths array

  • offsets – the array of offsets inside the shared memory starting from 0

  • lengths – the array of lengths of bytes should be retrieved

  • parallelism – the wanted degree of parallelism

Returns

rows of original bytes representation of shared memory, the width is the max given length, rows of other lengths are padded by ‘\0’.

offset_get()

Atomically get the bytes at specific offset given specific length

Parameters
  • offset – the offset inside the shared memory starting from 0

  • length – the length of bytes should be retrieved

Returns

bytes at specific offset.

offset_get_and_set()

Atomically get and set the bytes at specific offset given specific length

Parameters
  • value – new value in bytes

  • offset – the offset inside the shared memory starting from 0

Returns

bytes at specific offset previously.

offset_get_and_sets()

Atomically get the bytes at specific offsets given specific lengths

Parameters
  • values – rows of bytes at specific offsets, rows will be right trimmed according to lengths array

  • offsets – the array of offsets inside the shared memory starting from 0

  • lengths – the array of lengths of bytes should be retrieved

  • parallelism – the wanted degree of parallelism

Returns

rows of bytes at specific offsets, the width is the max given length, rows of other lengths are padded by ‘\0’.

offset_gets()

Atomically get the bytes at specific offsets given specific lengths

Parameters
  • offsets – the array of offsets inside the shared memory starting from 0

  • lengths – the array of lengths of bytes should be retrieved

  • parallelism – the wanted degree of parallelism

Returns

rows of bytes at specific offsets, the width is the max given length, rows of other lengths are padded by ‘\0’.

offset_memmove()

Set or read the data at specific offset given specific length using memcpy, it’s NOT atomic method the data can be any length incase you don’t need atomicity or should use other lengths

Parameters
  • mv – the data source as memoryview to read from or write to

  • offset – offset in the shared memory to read from or write to

  • io_flags – ‘i’ to write from the mv to the shared memory, ‘o’ to read from the shared memory to the mv

Returns

None

offset_sub_and_fetch()

substract and fetch atomically

Parameters
  • value – data to substract

  • offset – the offset inside the shared memory starting from 0 you need to add to,

Returns

difference of the 2 values

offset_sub_and_fetches()

substract and fetch atomically at specific offsets given specific lengths

Parameters
  • values – rows of bytes to substract, rows will be right trimmed according to lengths array

  • offsets – the array of offsets inside the shared memory starting from 0

  • lengths – the array of lengths of bytes should be retrieved

  • parallelism – the wanted degree of parallelism

Returns

rows of differences of the two bytes representation of values and shared memory bytes, the width is the max given length, rows of other lengths are padded by ‘\0’.

shared_atomic.atomic_shared_memory.shared_memory_offset_add_and_fetch()

increment and fetch atomically

Parameters
  • memory – target shared memory.

  • reference – the reference used in subprocess

  • value – data to add

  • offset – the offset inside the shared memory starting from 0

Returns

sum of the 2 values

shared_atomic.atomic_shared_memory.shared_memory_offset_bittest_and_reset()

test and reset the bit at offset atomically

Parameters
  • memory – target shared memory to change.

  • reference – the reference used in subprocess

  • left_offset – the offset inside the shared memory starting from 0

Returns

the initial value at the offset of memory

shared_atomic.atomic_shared_memory.shared_memory_offset_bittest_and_set()

test and set the bit at offset atomically

Parameters
  • memory – target shared memory to change.

  • reference – the reference used in subprocess

  • left_offset – the offset inside the shared memory starting from 0,

Returns

the initial value at the offset of memory

shared_atomic.atomic_shared_memory.shared_memory_offset_compare_and_set_value()

Compare and set atomically. This compares the contents of pointer with the contents of self at offset. If equal, the operation is a read-modify-write operation that writes bytes parameter value into self. If they are not equal, the operation is a read and the current contents of self are written into pointer.

Parameters
  • memory – target shared memory.

  • reference – the reference used in subprocess

  • i – the value to set

  • n – the value to be compared with

  • offset – the offset inside the shared memory starting from 0 you need to compare and set,

Returns

the initial value at the offset of memory

shared_atomic.atomic_shared_memory.shared_memory_offset_fetch_and_add()

fetch and increment atomically

Parameters
  • memory – target shared memory to change.

  • reference – the reference used in subprocess

  • value – data to add

  • offset – the offset inside the shared memory starting from 0

Returns

the initial value at the offset of memory

shared_atomic.atomic_shared_memory.shared_memory_offset_fetch_and_and()

fetch and and atomically

Parameters
  • memory – target shared memory to change.

  • reference – the reference used in subprocess

  • value – data to and

  • offset – the offset inside the shared memory starting from 0

Returns

the initial value at the offset of memory

shared_atomic.atomic_shared_memory.shared_memory_offset_fetch_and_or()

fetch and or atomically

Parameters
  • memory – target shared memory to change.

  • reference – the reference used in subprocess

  • value – data to or

  • offset – the offset inside the shared memory starting from 0

Returns

the initial value at the offset of memory

shared_atomic.atomic_shared_memory.shared_memory_offset_fetch_and_sub()

fetch and substract atomically

Parameters
  • memory – target shared memory to change.

  • reference – the reference used in subprocess

  • value – data to substract

  • offset – the offset inside the shared memory starting from 0

Returns

the initial value at the offset of memory

shared_atomic.atomic_shared_memory.shared_memory_offset_fetch_and_xor()

fetch and xor atomically

Parameters
  • memory – target shared memory to change.

  • reference – the reference used in subprocess

  • value – data to xor

  • offset – the offset inside the shared memory starting from 0

Returns

the initial value at the offset of memory

shared_atomic.atomic_shared_memory.shared_memory_offset_get()

Atomically get the bytes at specific offset given specific length

Parameters
  • memory – target shared memory.

  • reference – the reference used in subprocess

  • offset – the offset inside the shared memory starting from 0

  • length – the length of bytes should be retrieved

Returns

bytes at specific offset.

shared_atomic.atomic_shared_memory.shared_memory_offset_get_and_set()

Atomically set the bytes at specific offset an get the original value

Parameters
  • memory – target shared memory.

  • reference – the reference used in subprocess

  • value – new value in bytes

  • offset – the offset inside the shared memory starting from 0

Returns

bytes at specific offset previously.

shared_atomic.atomic_shared_memory.shared_memory_offset_sub_and_fetch()

substract and fetch atomically

Parameters
  • memory – target shared memory.

  • reference – the reference used in subprocess

  • value – data to substract

  • offset – the offset inside the shared memory starting from 0

Returns

difference of the 2 values