Class

class AtomicBool

public class AtomicBool

Description: Provides functions related to atomic operations of the Bool class.

init(Bool)

public init(val: Bool)

Description: Constructs an instance of the atomic type AtomicBool that encapsulates the Bool data type. The initial value of the internal data for the instance is the value of the input parameter val.

Parameters:

  • val: Bool: initial value of the atomic type

func compareAndSwap(Bool, Bool)

public func compareAndSwap(old: Bool, new: Bool): Bool

Description: Performs a Compare and Swap (CAS) operation using default memory ordering.

The value of the atomic type and the value specified by the old parameter are compared for equality. If they are equal, the value specified by the new parameter is written and true is returned. Otherwise, no value is written and false is returned.

Parameters:

  • old: Bool: value to be compared with the atomic type instance
  • new: Bool: value to be written to the atomic type when the two values are equal

Returns:

  • Bool: If the swap is successful after comparison, true is returned. Otherwise, false is returned.

func compareAndSwap(Bool, Bool, MemoryOrder, MemoryOrder)

public func compareAndSwap(old: Bool, new: Bool, successOrder!: MemoryOrder, failureOrder!: MemoryOrder): Bool

Description: Performs a CAS operation using the memory ordering specified by successOrder used upon success and the memory ordering specified by failureOrder used upon failure.

The value of the atomic type and the value specified by the old parameter are compared for equality. If they are equal, the value specified by the new parameter is written and true is returned. Otherwise, no value is written and false is returned.

Parameters:

  • old: Bool: value to be compared with the atomic type instance
  • new: Bool: value to be written to the atomic type when the two values are equal
  • successOrder!: MemoryOrder: When the CAS operation is successful, the memory ordering required for the read > modify > write operation is executed.
  • failureOrder!: MemoryOrder: When the CAS operation fails, the memory ordering required for the read operation is executed.

Returns:

  • Bool: If the swap is successful after comparison, true is returned. Otherwise, false is returned.

func load()

public func load(): Bool

Description: Reads the value of an atomic type using the default memory ordering.

Returns:

  • Bool: value of the atomic type

func load(MemoryOrder)

public func load(memoryOrder!: MemoryOrder): Bool

Description: Reads the value of an atomic type using the memory ordering specified by the memoryOrder parameter.

Parameters:

  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • Bool: value of the atomic type

func store(Bool)

public func store(val: Bool): Unit

Description: Writes the value specified by the val parameter to an atomic type using the default memory ordering.

Parameters:

  • val: Bool: value to be written to an atomic type

func store(Bool, MemoryOrder)

public func store(val: Bool, memoryOrder!: MemoryOrder): Unit

Description: Writes the value specified by the val parameter to an atomic type using the memory ordering specified by the memoryOrder parameter.

Parameters:

  • val: Bool: value to be written to an atomic type
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

func swap(Bool)

public func swap(val: Bool): Bool

Description: Performs a swap operation using the default memory ordering to write the value specified by the val parameter to an atomic type, and returns the value before the writing.

Parameters:

  • val: Bool: value to be written to an atomic type

Returns:

  • Bool: value before writing

func swap(Bool, MemoryOrder)

public func swap(val: Bool, memoryOrder!: MemoryOrder): Bool

Description: Performs a swap operation using the memory ordering specified by the memoryOrder parameter to write the value specified by the val parameter to an atomic type, and returns the value before writing.

Parameters:

  • val: Bool: value to be written to an atomic type
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • Bool: value before writing

class AtomicInt16

public class AtomicInt16

Description: Provides functions related to atomic operations of the Int16 class.

init(Int16)

public init(val: Int16)

Description: Constructs an instance of the atomic type AtomicInt16 that encapsulates the data type Int16. The initial value of the internal data for the instance is the value of the input parameter val.

Parameters:

  • val: Int16: initial value of the atomic type

func compareAndSwap(Int16, Int16)

public func compareAndSwap(old: Int16, new: Int16): Bool

Description: Performs a CAS operation using the default memory ordering.

The value of the atomic type and the value specified by the old parameter are compared for equality. If they are equal, the value specified by the new parameter is written and true is returned. Otherwise, no value is written and false is returned.

Parameters:

  • old: Int16: value to be compared with the atomic type instance
  • new: Int16: value to be written to the atomic type when the two values are equal

Returns:

  • Bool: If the swap is successful after comparison, true is returned. Otherwise, false is returned.

func compareAndSwap(Int16, Int16, MemoryOrder, MemoryOrder)

public func compareAndSwap(old: Int16, new: Int16, successOrder!: MemoryOrder, failureOrder!: MemoryOrder): Bool

Description: Performs a CAS operation using the memory ordering specified by successOrder used upon success and the memory ordering specified by failureOrder used upon failure.

The value of the atomic type and the value specified by the old parameter are compared for equality. If they are equal, the value specified by the new parameter is written and true is returned. Otherwise, no value is written and false is returned.

Parameters:

  • old: Int16: value to be compared with the atomic type instance
  • new: Int16: value to be written to the atomic type when the two values are equal
  • successOrder!: MemoryOrder: When the CAS operation is successful, the memory ordering required for the read > modify > write operation is executed.
  • failureOrder!: MemoryOrder: When the CAS operation fails, the memory ordering required for the read operation is executed.

Returns:

  • Bool: If the swap is successful after comparison, true is returned. Otherwise, false is returned.

func fetchAdd(Int16)

public func fetchAdd(val: Int16): Int16

Description: Adds the value of an atomic type to the val parameter using the default memory ordering, writes the result to the atomic type instance, and returns the value before the addition.

Parameters:

  • val: Int16: value to be added to the atomic type instance

Returns:

  • Int16: value before the addition

func fetchAdd(Int16, MemoryOrder)

public func fetchAdd(val: Int16, memoryOrder!: MemoryOrder): Int16

Description: Adds the value of an atomic type to the val parameter using the memory ordering specified by the memoryOrder parameter, writes the result to the atomic type instance, and returns the value before the addition.

Parameters:

  • val: Int16: value to be added to the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • Int16: value before the addition

func fetchAnd(Int16)

public func fetchAnd(val: Int16): Int16

Description: Performs an AND operation on the value of the current atomic type instance and the val parameter using the default memory ordering, writes the result to the current atomic type instance, and returns the value before the AND operation.

Parameters:

  • val: Int16: value to be ANDed with the atomic type instance

Returns:

  • Int16: value before the AND operation

func fetchAnd(Int16, MemoryOrder)

public func fetchAnd(val: Int16, memoryOrder!: MemoryOrder): Int16

Description: Performs an AND operation on the value of the current atomic type instance and the val parameter using the memory ordering specified by the memoryOrder parameter, writes the result to the current atomic type instance, and returns the value before the AND operation.

Parameters:

  • val: Int16: value to be ANDed with the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • Int16: value before the AND operation

func fetchOr(Int16)

public func fetchOr(val: Int16): Int16

Description: Performs an OR operation on the value of the current atomic type instance and the val parameter using the default memory ordering, writes the result to the current atomic type instance, and returns the value before the OR operation.

Parameters:

  • val: Int16: value to be ORed with the atomic type instance

Returns:

  • Int16: value before the OR operation

func fetchOr(Int16, MemoryOrder)

public func fetchOr(val: Int16, memoryOrder!: MemoryOrder): Int16

Description: Performs an OR operation on the value of the current atomic type instance and the val parameter using the memory ordering specified by the memoryOrder parameter, writes the result to the current atomic type instance, and returns the value before the OR operation.

Parameters:

  • val: Int16: value to be ORed with the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • Int16: value before the OR operation

func fetchSub(Int16)

public func fetchSub(val: Int16): Int16

Description: Uses the value of an atomic type as the minuend and the val parameter as the subtrahend to perform subtraction using the default memory ordering, writes the result to the current atomic type instance, and returns the value before the subtraction.

Parameters:

  • val: Int16: value to be subtracted from the atomic type instance

Returns:

  • Int16: value before the subtraction

func fetchSub(Int16, MemoryOrder)

public func fetchSub(val: Int16, memoryOrder!: MemoryOrder): Int16

Description: Uses the value of an atomic type as the minuend and the val parameter as the subtrahend to perform subtraction using the memory ordering specified by the memoryOrder parameter, writes the result to the current atomic type instance, and returns the value before the subtraction.

Parameters:

  • val: Int16: value to be subtracted from the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • Int16: value before the subtraction

func fetchXor(Int16)

public func fetchXor(val: Int16): Int16

Description: Performs an XOR operation on the value of the current atomic type instance and the val parameter using the default memory ordering, writes the result to the current atomic type instance, and returns the value before the XOR operation.

Parameters:

  • val: Int16: value to be XORed with the atomic type instance

Returns:

  • Int16: value before the XOR operation

func fetchXor(Int16, MemoryOrder)

public func fetchXor(val: Int16, memoryOrder!: MemoryOrder): Int16

Description: Performs an XOR operation on the value of the current atomic type instance and the val parameter using the memory ordering specified by the memoryOrder parameter, writes the result to the current atomic type instance, and returns the value before the XOR operation.

Parameters:

  • val: Int16: value to be XORed with the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • Int16: value before the XOR operation

func load()

public func load(): Int16

Description: Reads the value of an atomic type using the default memory ordering.

Returns:

  • Int16: value of the atomic type

func load(MemoryOrder)

public func load(memoryOrder!: MemoryOrder): Int16

Description: Reads the value of an atomic type with the memory ordering specified by the memoryOrder parameter.

Parameters:

  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • Int16: value of the atomic type

func store(Int16)

public func store(val: Int16): Unit

Description: Writes the value specified by the val parameter to an atomic type using the default memory ordering.

Parameters:

  • val: Int16: value to be written to an atomic type

func store(Int16, MemoryOrder)

public func store(val: Int16, memoryOrder!: MemoryOrder): Unit

Description: Writes the value specified by the val parameter to an atomic type using the memory ordering specified by the memoryOrder parameter.

Parameters:

  • val: Int16: value to be written to an atomic type
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

func swap(Int16)

public func swap(val: Int16): Int16

Description: Performs a swap operation to write the value specified by the val parameter to an atomic type using the default memory ordering, and returns the value before the writing.

Parameters:

  • val: Int16: value to be written to an atomic type

Returns:

  • Int16: value before writing

func swap(Int16, MemoryOrder)

public func swap(val: Int16, memoryOrder!: MemoryOrder): Int16

Description: Performs a swap operation to write the value specified by the val parameter to an atomic type using the memory ordering specified by the memoryOrder parameter, and returns the value before the writing.

Parameters:

  • val: Int16: value to be written to an atomic type
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • Int16: value before writing

class AtomicInt32

public class AtomicInt32

Description: Provides functions related to atomic operations of the Int32 class.

init(Int32)

public init(val: Int32)

Description: Constructs an instance of the atomic type AtomicInt32 that encapsulates the data type Int32. The initial value of the internal data for the instance is the value of the input parameter val.

Parameters:

  • val: Int32: initial value of the atomic type

func compareAndSwap(Int32, Int32)

public func compareAndSwap(old: Int32, new: Int32): Bool

Description: Performs a CAS operation using the default memory ordering.

The value of the atomic type and the value specified by the old parameter are compared for equality. If they are equal, the value specified by the new parameter is written and true is returned. Otherwise, no value is written and false is returned.

Parameters:

  • old: Int32: value to be compared with the atomic type instance
  • new: Int32: value to be written to the atomic type when the two values are equal

Returns:

  • Bool: If the swap is successful after comparison, true is returned. Otherwise, false is returned.

func compareAndSwap(Int32, Int32, MemoryOrDer, MemoryOrder)

public func compareAndSwap(old: Int32, new: Int32, successOrder!: MemoryOrder, failureOrder!: MemoryOrder): Bool

Description: Performs a CAS operation using the memory ordering specified by successOrder used upon success and the memory ordering specified by failureOrder used upon failure.

The value of the atomic type and the value specified by the old parameter are compared for equality. If they are equal, the value specified by the new parameter is written and true is returned. Otherwise, no value is written and false is returned.

Parameters:

  • old: Int32: value to be compared with the atomic type instance
  • new: Int32: value to be written to the atomic type when the two values are equal
  • successOrder!: MemoryOrder: When the CAS operation is successful, the memory ordering required for the read > modify > write operation is executed.
  • failureOrder!: MemoryOrder: When the CAS operation fails, the memory ordering required for the read operation is executed.

Returns:

  • Bool: If the swap is successful after comparison, true is returned. Otherwise, false is returned.

func fetchAdd(Int32)

public func fetchAdd(val: Int32): Int32

Description: Adds the value of an atomic type to the val parameter using the default memory ordering, writes the result to the atomic type instance, and returns the value before the addition.

Parameters:

  • val: Int32: value to be added to the atomic type instance

Returns:

  • Int32: value before the addition

func fetchAdd(Int32, MemoryOrder)

public func fetchAdd(val: Int32, memoryOrder!: MemoryOrder): Int32

Description: Adds the value of an atomic type to the val parameter using the memory ordering specified by the memoryOrder parameter, writes the result to the atomic type instance, and returns the value before the addition.

Parameters:

  • val: Int32: value to be added to the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • Int32: value before the addition

func fetchAnd(Int32)

public func fetchAnd(val: Int32): Int32

Description: Performs an AND operation on the value of the current atomic type instance and the val parameter using the default memory ordering, writes the result to the current atomic type instance, and returns the value before the AND operation.

Parameters:

  • val: Int32: value to be ANDed with the atomic type instance

Returns:

  • Int32: value before the AND operation

func fetchAnd(Int32, MemoryOrder)

public func fetchAnd(val: Int32, memoryOrder!: MemoryOrder): Int32

Description: Performs an AND operation on the value of the current atomic type instance and the val parameter using the memory ordering specified by the memoryOrder parameter, writes the result to the current atomic type instance, and returns the value before the AND operation.

Parameters:

  • val: Int32: value to be ANDed with the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • Int32: value before the AND operation

func fetchOr(Int32)

public func fetchOr(val: Int32): Int32

Description: Performs an OR operation on the value of the current atomic type instance and the val parameter using the default memory ordering, writes the result to the current atomic type instance, and returns the value before the OR operation.

Parameters:

  • val: Int32: value to be ORed with the atomic type instance

Returns:

  • Int32: value before the OR operation

func fetchOr(Int32, MemoryOrder)

public func fetchOr(val: Int32, memoryOrder!: MemoryOrder): Int32

Description: Performs an OR operation on the value of the current atomic type instance and the val parameter using the memory ordering specified by the memoryOrder parameter, writes the result to the current atomic type instance, and returns the value before the OR operation.

Parameters:

  • val: Int32: value to be ORed with the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • Int32: value before the OR operation

func fetchSub(Int32)

public func fetchSub(val: Int32): Int32

Description: Uses the value of an atomic type as the minuend and the val parameter as the subtrahend to perform subtraction using the default memory ordering, writes the result to the current atomic type instance, and returns the value before the subtraction.

Parameters:

  • val: Int32: value to be subtracted from the atomic type instance

Returns:

  • Int32: value before the subtraction

func fetchSub(Int32, MemoryOrder)

public func fetchSub(val: Int32, memoryOrder!: MemoryOrder): Int32

Description: Uses the value of an atomic type as the minuend and the val parameter as the subtrahend to perform subtraction using the memory ordering specified by the memoryOrder parameter, writes the result to the current atomic type instance, and returns the value before the subtraction.

Parameters:

  • val: Int32: value to be subtracted from the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • Int32: value before the subtraction

func fetchXor(Int32)

public func fetchXor(val: Int32): Int32

Description: Performs an XOR operation on the value of the current atomic type instance and the val parameter using the default memory ordering, writes the result to the current atomic type instance, and returns the value before the XOR operation.

Parameters:

  • val: Int32: value to be XORed with the atomic type instance

Returns:

  • Int32: value before the XOR operation

func fetchXor(Int32, MemoryOrder)

public func fetchXor(val: Int32, memoryOrder!: MemoryOrder): Int32

Description: Performs an XOR operation on the value of the current atomic type instance and the val parameter using the memory ordering specified by the memoryOrder parameter, writes the result to the current atomic type instance, and returns the value before the XOR operation.

Parameters:

  • val: Int32: value to be XORed with the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • Int32: value before the XOR operation

func load()

public func load(): Int32

Description: Reads the value of an atomic type using the default memory ordering.

Returns:

  • Int32: value of the atomic type

func load(MemoryOrder)

public func load(memoryOrder!: MemoryOrder): Int32

Description: Reads the value of an atomic type with the memory ordering specified by the memoryOrder parameter.

Parameters:

  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • Int32: value of the atomic type

func store(Int32)

public func store(val: Int32): Unit

Description: Writes the value specified by the val parameter to an atomic type using the default memory ordering.

Parameters:

  • val: Int32: value to be written to an atomic type

func store(Int32, MemoryOrder)

public func store(val: Int32, memoryOrder!: MemoryOrder): Unit

Description: Writes the value specified by the val parameter to an atomic type using the memory ordering specified by the memoryOrder parameter.

Parameters:

  • val: Int32: value to be written to an atomic type
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

func swap(Int32)

public func swap(val: Int32): Int32

Description: Performs a swap operation to write the value specified by the val parameter to an atomic type using the default memory ordering, and returns the value before the writing.

Parameters:

  • val: Int32: value to be written to an atomic type

Returns:

  • Int32: value before writing

func swap(Int32, MemoryOrder)

public func swap(val: Int32, memoryOrder!: MemoryOrder): Int32

Description: Performs a swap operation to write the value specified by the val parameter to an atomic type using the memory ordering specified by the memoryOrder parameter, and returns the value before the writing.

Parameters:

  • val: Int32: value to be written to an atomic type
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • Int32: value before writing

class AtomicInt64

public class AtomicInt64

Description: Provides functions related to atomic operations of the Int64 class.

init(Int64)

public init(val: Int64)

Description: Constructs an instance of the atomic type AtomicInt64 that encapsulates the data type Int64. The initial value of the internal data for the instance is the value of the input parameter val.

Parameters:

  • val: Int64: initial value of the atomic type

func compareAndSwap(Int64, Int64)

public func compareAndSwap(old: Int64, new: Int64): Bool

Description: Performs a CAS operation using the default memory ordering.

The value of the atomic type and the value specified by the old parameter are compared for equality. If they are equal, the value specified by the new parameter is written and true is returned. Otherwise, no value is written and false is returned.

Parameters:

  • old: Int64: value to be compared with the atomic type instance
  • new: Int64: value to be written to the atomic type when the two values are equal

Returns:

  • Bool: If the swap is successful after comparison, true is returned. Otherwise, false is returned.

func compareAndSwap(Int64, Int64, MemoryOrder, MemoryOrder)

public func compareAndSwap(old: Int64, new: Int64, successOrder!: MemoryOrder, failureOrder!: MemoryOrder): Bool

Description: Performs a CAS operation using the memory ordering specified by successOrder used upon success and the memory ordering specified by failureOrder used upon failure.

The value of the atomic type and the value specified by the old parameter are compared for equality. If they are equal, the value specified by the new parameter is written and true is returned. Otherwise, no value is written and false is returned.

Parameters:

  • old: Int64: value to be compared with the atomic type instance
  • new: Int64: value to be written to the atomic type when the two values are equal
  • successOrder!: MemoryOrder: When the CAS operation is successful, the memory ordering required for the read > modify > write operation is executed.
  • failureOrder!: MemoryOrder: When the CAS operation fails, the memory ordering required for the read operation is executed.

Returns:

  • Bool: If the swap is successful after comparison, true is returned. Otherwise, false is returned.

func fetchAdd(Int64)

public func fetchAdd(val: Int64): Int64

Description: Adds the value of an atomic type to the val parameter using the default memory ordering, writes the result to the atomic type instance, and returns the value before the addition.

Parameters:

  • val: Int64: value to be added to the atomic type instance

Returns:

  • Int64: value before the addition

func fetchAdd(Int64, MemoryOrder)

public func fetchAdd(val: Int64, memoryOrder!: MemoryOrder): Int64

Description: Adds the value of an atomic type to the val parameter using the memory ordering specified by the memoryOrder parameter, writes the result to the atomic type instance, and returns the value before the addition.

Parameters:

  • val: Int64: value to be added to the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • Int64: value before the addition

func fetchAnd(Int64)

public func fetchAnd(val: Int64): Int64

Description: Performs an AND operation on the value of the current atomic type instance and the val parameter using the default memory ordering, writes the result to the current atomic type instance, and returns the value before the AND operation.

Parameters:

  • val: Int64: value to be ANDed with the atomic type instance

Returns:

  • Int64: value before the AND operation

func fetchAnd(Int64, MemoryOrder)

public func fetchAnd(val: Int64, memoryOrder!: MemoryOrder): Int64

Description: Performs an AND operation on the value of the current atomic type instance and the val parameter using the memory ordering specified by the memoryOrder parameter, writes the result to the current atomic type instance, and returns the value before the AND operation.

Parameters:

  • val: Int64: value to be ANDed with the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • Int64: value before the AND operation

func fetchOr(Int64)

public func fetchOr(val: Int64): Int64

Description: Performs an OR operation on the value of the current atomic type instance and the val parameter using the default memory ordering, writes the result to the current atomic type instance, and returns the value before the OR operation.

Parameters:

  • val: Int64: value to be ORed with the atomic type instance

Returns:

  • Int64: value before the OR operation

func fetchOr(Int64, MemoryOrder)

public func fetchOr(val: Int64, memoryOrder!: MemoryOrder): Int64

Description: Performs an OR operation on the value of the current atomic type instance and the val parameter using the memory ordering specified by the memoryOrder parameter, writes the result to the current atomic type instance, and returns the value before the OR operation.

Parameters:

  • val: Int64: value to be ORed with the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • Int64: value before the OR operation

func fetchSub(Int64)

public func fetchSub(val: Int64): Int64

Description: Uses the value of an atomic type as the minuend and the val parameter as the subtrahend to perform subtraction using the default memory ordering, writes the result to the current atomic type instance, and returns the value before the subtraction.

Parameters:

  • val: Int64: value to be subtracted from the atomic type instance

Returns:

  • Int64: value before the subtraction

func fetchSub(Int64, MemoryOrder)

public func fetchSub(val: Int64, memoryOrder!: MemoryOrder): Int64

Description: Uses the value of an atomic type as the minuend and the val parameter as the subtrahend to perform subtraction using the memory ordering specified by the memoryOrder parameter, writes the result to the current atomic type instance, and returns the value before the subtraction.

Parameters:

  • val: Int64: value to be subtracted from the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • Int64: value before the subtraction

func fetchXor(Int64)

public func fetchXor(val: Int64): Int64

Description: Performs an XOR operation on the value of the current atomic type instance and the val parameter using the default memory ordering, writes the result to the current atomic type instance, and returns the value before the XOR operation.

Parameters:

  • val: Int64: value to be XORed with the atomic type instance

Returns:

  • Int64: value before the XOR operation

func fetchXor(Int64, MemoryOrder)

public func fetchXor(val: Int64, memoryOrder!: MemoryOrder): Int64

Description: Performs an XOR operation on the value of the current atomic type instance and the val parameter using the memory ordering specified by the memoryOrder parameter, writes the result to the current atomic type instance, and returns the value before the XOR operation.

Parameters:

  • val: Int64: value to be XORed with the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • Int64: value before the XOR operation

func load()

public func load(): Int64

Description: Reads the value of an atomic type using the default memory ordering.

Returns:

  • Int64: value of the atomic type

func load(MemoryOrder)

public func load(memoryOrder!: MemoryOrder): Int64

Description: Reads the value of an atomic type with the memory ordering specified by the memoryOrder parameter.

Parameters:

  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • Int64: value of the atomic type

func store(Int64)

public func store(val: Int64): Unit

Description: Writes the value specified by the val parameter to an atomic type using the default memory ordering.

Parameters:

  • val: Int64: value to be written to an atomic type

func store(Int64, MemoryOrder)

public func store(val: Int64, memoryOrder!: MemoryOrder): Unit

Description: Writes the value specified by the val parameter to an atomic type using the memory ordering specified by the memoryOrder parameter.

Parameters:

  • val: Int64: value to be written to an atomic type
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

func swap(Int64)

public func swap(val: Int64): Int64

Description: Performs a swap operation to write the value specified by the val parameter to an atomic type using the default memory ordering, and returns the value before the writing.

Parameters:

  • val: Int64: value to be written to an atomic type

Returns:

  • Int64: value before writing

func swap(Int64, MemoryOrder)

public func swap(val: Int64, memoryOrder!: MemoryOrder): Int64

Description: Performs a swap operation to write the value specified by the val parameter to an atomic type using the memory ordering specified by the memoryOrder parameter, and returns the value before the writing.

Parameters:

  • val: Int64: value to be written to an atomic type
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • Int64: value before writing

class AtomicInt8

public class AtomicInt8

Description: Provides functions related to atomic operations of the Int8 class.

init(Int8)

public init(val: Int8)

Description: Constructs an instance of the atomic type AtomicInt8 that encapsulates the data type Int8. The initial value of the internal data for the instance is the value of the input parameter val.

Parameters:

  • val: Int8: initial value of the atomic type

func compareAndSwap(Int8, Int8)

public func compareAndSwap(old: Int8, new: Int8): Bool

Description: Performs a CAS operation using the default memory ordering.

The value of the atomic type and the value specified by the old parameter are compared for equality. If they are equal, the value specified by the new parameter is written and true is returned. Otherwise, no value is written and false is returned.

Parameters:

  • old: Int8: value to be compared with the atomic type instance
  • new: Int8: value to be written to the atomic type when the two values are equal

Returns:

  • Bool: If the swap is successful after comparison, true is returned. Otherwise, false is returned.

func compareAndSwap(Int8, Int8, MemoryOrder, MemoryOrder)

public func compareAndSwap(old: Int8, new: Int8, successOrder!: MemoryOrder, failureOrder!: MemoryOrder): Bool

Description: Performs a CAS operation using the memory ordering specified by successOrder used upon success and the memory ordering specified by failureOrder used upon failure.

The value of the atomic type and the value specified by the old parameter are compared for equality. If they are equal, the value specified by the new parameter is written and true is returned. Otherwise, no value is written and false is returned.

Parameters:

  • old: Int8: value to be compared with the atomic type instance
  • new: Int8: value to be written to the atomic type when the two values are equal
  • successOrder!: MemoryOrder: When the CAS operation is successful, the memory ordering required for the read > modify > write operation is executed.
  • failureOrder!: MemoryOrder: When the CAS operation fails, the memory ordering required for the read operation is executed.

Returns:

  • Bool: If the swap is successful after comparison, true is returned. Otherwise, false is returned.

func fetchAdd(Int8)

public func fetchAdd(val: Int8): Int8

Description: Adds the value of an atomic type to the val parameter using the default memory ordering, writes the result to the atomic type instance, and returns the value before the addition.

Parameters:

  • val: Int8: value to be added to the atomic type instance

Returns:

  • Int8: value before the addition

func fetchAdd(Int8, MemoryOrder)

public func fetchAdd(val: Int8, memoryOrder!: MemoryOrder): Int8

Description: Adds the value of an atomic type to the val parameter using the memory ordering specified by the memoryOrder parameter, writes the result to the atomic type instance, and returns the value before the addition.

Parameters:

  • val: Int8: value to be added to the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • Int8: value before the addition

func fetchAnd(Int8)

public func fetchAnd(val: Int8): Int8

Description: Performs an AND operation on the value of the current atomic type instance and the val parameter using the default memory ordering, writes the result to the current atomic type instance, and returns the value before the AND operation.

Parameters:

  • val: Int8: value to be ANDed with the atomic type instance

Returns:

  • Int8: value before the AND operation

func fetchAnd(Int8, MemoryOrder)

public func fetchAnd(val: Int8, memoryOrder!: MemoryOrder): Int8

Description: Performs an AND operation on the value of the current atomic type instance and the val parameter using the memory ordering specified by the memoryOrder parameter, writes the result to the current atomic type instance, and returns the value before the AND operation.

Parameters:

  • val: Int8: value to be ANDed with the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • Int8: value before the AND operation

func fetchOr(Int8)

public func fetchOr(val: Int8): Int8

Description: Performs an OR operation on the value of the current atomic type instance and the val parameter using the default memory ordering, writes the result to the atomic type instance, and returns the value before the OR operation.

Parameters:

  • val: Int8: value to be ORed with the atomic type instance

Returns:

  • Int8: value before the OR operation

func fetchOr(Int8, MemoryOrder)

public func fetchOr(val: Int8, memoryOrder!: MemoryOrder): Int8

Description: Performs an OR operation on the value of the atomic type instance and the val parameter using the memory ordering specified by the memoryOrder parameter, writes the result to the atomic type instance, and returns the value before the OR operation.

Parameters:

  • val: Int8: value to be ORed with the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • Int8: value before the OR operation

func fetchSub(Int8)

public func fetchSub(val: Int8): Int8

Description: Uses the value of an atomic type as the minuend and the val parameter as the subtrahend to perform subtraction using the default memory ordering, writes the result to the current atomic type instance, and returns the value before the subtraction.

Parameters:

  • val: Int8: value to be subtracted from the atomic type instance

Returns:

  • Int8: value before the subtraction

func fetchSub(Int8, MemoryOrder)

public func fetchSub(val: Int8, memoryOrder!: MemoryOrder): Int8

Description: Uses the value of an atomic type as the minuend and the val parameter as the subtrahend to perform subtraction using the memory ordering specified by the memoryOrder parameter, writes the result to the current atomic type instance, and returns the value before the subtraction.

Parameters:

  • val: Int8: value to be subtracted from the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • Int8: value before the subtraction

func fetchXor(Int8)

public func fetchXor(val: Int8): Int8

Description: Performs an XOR operation on the value of the current atomic type instance and the val parameter using the default memory ordering, writes the result to the current atomic type instance, and returns the value before the XOR operation.

Parameters:

  • val: Int8: value to be XORed with the atomic type instance

Returns:

  • Int8: value before the XOR operation

func fetchXor(Int8, MemoryOrder)

public func fetchXor(val: Int8, memoryOrder!: MemoryOrder): Int8

Description: Performs an XOR operation on the value of the current atomic type instance and the val parameter using the memory ordering specified by the memoryOrder parameter, writes the result to the current atomic type instance, and returns the value before the XOR operation.

Parameters:

  • val: Int8: value to be XORed with the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • Int8: value before the XOR operation

func load()

public func load(): Int8

Description: Reads the value of an atomic type using the default memory ordering.

Returns:

  • Int8: value of the atomic type

func load(MemoryOrder)

public func load(memoryOrder!: MemoryOrder): Int8

Description: Reads the value of an atomic type using the memory ordering specified by the memoryOrder parameter.

Parameters:

  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • Int8: value of the atomic type

func store(Int8)

public func store(val: Int8): Unit

Description: Writes the value specified by the val parameter to an atomic type using the default memory ordering.

Parameters:

  • val: Int8: value to be written to an atomic type

func store(Int8, MemoryOrder)

public func store(val: Int8, memoryOrder!: MemoryOrder): Unit

Description: Writes the value specified by the val parameter to an atomic type using the memory ordering specified by the memoryOrder parameter.

Parameters:

  • val: Int8: value to be written to an atomic type
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

func swap(Int8)

public func swap(val: Int8): Int8

Description: Performs a swap operation to write the value specified by the val parameter to an atomic type using the default memory ordering, and returns the value before the writing.

Parameters:

  • val: Int8: value to be written to an atomic type

Returns:

  • Int8: value before writing

func swap(Int8, MemoryOrder)

public func swap(val: Int8, memoryOrder!: MemoryOrder): Int8

Description: Performs a swap operation to write the value specified by the val parameter to an atomic type using the memory ordering specified by the memoryOrder parameter, and returns the value before the writing.

Parameters:

  • val: Int8: value to be written to an atomic type
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • Int8: value before writing

class AtomicOptionReference

public class AtomicOptionReference<T> where T <: Object

Description: Provides functions related to atomic operations of a reference class.

The reference class must be a subclass of Object.

init()

public init()

Description: Constructs an empty AtomicOptionReference instance.

init(Option<T>)

public init(val: Option<T>)

Description: Constructs an instance of the atomic type AtomicOptionReference that encapsulates the data type Option<T>. The initial value of the internal data for the instance is the value of the input parameter val.

Parameters:

  • val: Option<T>: initial value of the atomic type

func compareAndSwap(Option<T>, Option<T>)

public func compareAndSwap(old: Option<T>, new: Option<T>): Bool

Description: Performs a CAS operation using the default memory ordering.

The value of the atomic type and the value specified by the old parameter are compared for equality. If they are equal, the value specified by the new parameter is written and true is returned. Otherwise, no value is written and false is returned.

Parameters:

  • old: Option<T>: value to be compared with the atomic type instance
  • new: Option<T>: value to be written to the atomic type when the two values are equal

Returns:

  • Bool: If the swap is successful after comparison, true is returned. Otherwise, false is returned.

func compareAndSwap(Option<T>, Option<T>, MemoryOrder, MemoryOrder)

public func compareAndSwap(old: Option<T>, new: Option<T>, successOrder!: MemoryOrder, failureOrder!: MemoryOrder): Bool

Description: Performs a CAS operation using the memory ordering specified by successOrder used upon success and the memory ordering specified by failureOrder used upon failure.

The value of the atomic type and the value specified by the old parameter are compared for equality. If they are equal, the value specified by the new parameter is written and true is returned. Otherwise, no value is written and false is returned.

Parameters:

  • old: Option<T>: value to be compared with the atomic type instance
  • new: Option<T>: value to be written to the atomic type when the two values are equal
  • successOrder!: MemoryOrder: When the CAS operation is successful, the memory ordering required for the read > modify > write operation is executed.
  • failureOrder!: MemoryOrder: When the CAS operation fails, the memory ordering required for the read operation is executed.

Returns:

  • Bool: If the swap is successful after comparison, true is returned. Otherwise, false is returned.

func load()

public func load(): Option<T>

Description: Reads the value of an atomic type using the default memory ordering.

Returns:

  • Option<T>: value of the atomic type

func load(MemoryOrder)

public func load(memoryOrder!: MemoryOrder): Option<T>

Description: Reads the value of an atomic type using the memory ordering specified by the memoryOrder parameter.

Parameters:

  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • Option<T>: value of the atomic type

func store(Option<T>)

public func store(val: Option<T>): Unit

Description: Writes the value specified by the val parameter to an atomic type using the default memory ordering.

Parameters:

  • val: Option<T>: value to be written to an atomic type

func store(Option<T>, MemoryOrder)

public func store(val: Option<T>, memoryOrder!: MemoryOrder): Unit

Description: Writes the value specified by the val parameter to an atomic type using the memory ordering specified by the memoryOrder parameter.

Parameters:

  • val: Option<T>: value to be written to an atomic type
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

func swap(Option<T>)

public func swap(val: Option<T>): Option<T>

Description: Performs a swap operation to write the value specified by the val parameter to an atomic type using the default memory ordering, and returns the value before the writing.

Parameters:

  • val: Option<T>: value to be written to an atomic type

Returns:

  • Option<T>: value before writing

func swap(Option<T>, MemoryOrder)

public func swap(val: Option<T>, memoryOrder!: MemoryOrder): Option<T>

Description: Performs a swap operation to write the value specified by the val parameter to an atomic type using the memory ordering specified by the memoryOrder parameter, and returns the value before the writing.

Parameters:

  • val: Option<T>: value to be written to an atomic type
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • Option<T>: value before writing

class AtomicReference

public class AtomicReference<T> where T <: Object

Description: Provides functions related to atomic operations of a reference class.

The reference class must be a subclass of Object.

init(T)

public init(val: T)

Description: Constructs an instance of the atomic type AtomicReference that encapsulates the data type T. The initial value of the internal data for the instance is the value of the input parameter val.

Parameters:

  • val: T: initial value of the atomic type

func compareAndSwap(T, T)

public func compareAndSwap(old: T, new: T): Bool

Description: Performs a CAS operation using the default memory ordering.

The value of the atomic type and the value specified by the old parameter are compared for equality. If they are equal, the value specified by the new parameter is written and true is returned. Otherwise, no value is written and false is returned.

Parameters:

  • old: T: value to be compared with the atomic type instance
  • new: T: value to be written to the atomic type when the two values are equal

Returns:

  • Bool: If the swap is successful after comparison, true is returned. Otherwise, false is returned.

func compareAndSwap(T, T, MemoryOrder, MemoryOrder)

public func compareAndSwap(old: T, new: T, successOrder!: MemoryOrder, failureOrder!: MemoryOrder): Bool

Description: Performs a CAS operation using the memory ordering specified by successOrder used upon success and the memory ordering specified by failureOrder used upon failure.

The value of the atomic type and the value specified by the old parameter are compared for equality. If they are equal, the value specified by the new parameter is written and true is returned. Otherwise, no value is written and false is returned.

Parameters:

  • old: T: value to be compared with the atomic type instance
  • new: T: value to be written to the atomic type when the two values are equal
  • successOrder!: MemoryOrder: When the CAS operation is successful, the memory ordering required for the read > modify > write operation is executed.
  • failureOrder!: MemoryOrder: When the CAS operation fails, the memory ordering required for the read operation is executed.

Returns:

  • Bool: If the swap is successful after comparison, true is returned. Otherwise, false is returned.

func load()

public func load(): T

Description: Reads the value of an atomic type using the default memory ordering.

Returns:

  • T: value of the atomic type

func load(MemoryOrder)

public func load(memoryOrder!: MemoryOrder): T

Description: Reads the value of an atomic type using the memory ordering specified by the memoryOrder parameter.

Parameters:

  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • T: value of the atomic type

func store(T)

public func store(val: T): Unit

Description: Writes the value specified by the val parameter to an atomic type using the default memory ordering.

Parameters:

  • val: T: value to be written to an atomic type

func store(T, MemoryOrder)

public func store(val: T, memoryOrder!: MemoryOrder): Unit

Description: Writes the value specified by the val parameter to an atomic type using the memory ordering specified by the memoryOrder parameter.

Parameters:

  • val: T: value to be written to an atomic type
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

func swap(T)

public func swap(val: T): T

Description: Performs a swap operation to write the value specified by the val parameter to an atomic type using the default memory ordering, and returns the value before the writing.

Parameters:

  • val: T: value to be written to an atomic type

Returns:

  • T: value before writing

func swap(T, MemoryOrder)

public func swap(val: T, memoryOrder!: MemoryOrder): T

Description: Performs a swap operation to write the value specified by the val parameter to an atomic type using the memory ordering specified by the memoryOrder parameter, and returns the value before the writing.

Parameters:

  • val: T: value to be written to an atomic type
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • T: value before writing

class AtomicUInt16

public class AtomicUInt16

Description: Provides functions related to atomic operations of the UInt16 class.

init(UInt16)

public init(val: UInt16)

Description: Constructs an instance of the atomic type AtomicUInt16 that encapsulates the data type UInt16. The initial value of the internal data for the instance is the value of the input parameter val.

Parameters:

  • val: UInt16: initial value of the atomic type

func compareAndSwap(UInt16, UInt16)

public func compareAndSwap(old: UInt16, new: UInt16): Bool

Description: Performs a CAS operation using the default memory ordering.

The value of the atomic type and the value specified by the old parameter are compared for equality. If they are equal, the value specified by the new parameter is written and true is returned. Otherwise, no value is written and false is returned.

Parameters:

  • old: UInt16: value to be compared with the atomic type instance
  • new: UInt16: value to be written to the atomic type when the two values are equal

Returns:

  • Bool: If the swap is successful after comparison, true is returned. Otherwise, false is returned.

func compareAndSwap(UInt16, UInt16, MemoryOrder, MemoryOrder)

public func compareAndSwap(old: UInt16, new: UInt16, successOrder!: MemoryOrder, failureOrder!: MemoryOrder): Bool

Description: Performs a CAS operation using the memory ordering specified by successOrder used upon success and the memory ordering specified by failureOrder used upon failure.

The value of the atomic type and the value specified by the old parameter are compared for equality. If they are equal, the value specified by the new parameter is written and true is returned. Otherwise, no value is written and false is returned.

Parameters:

  • old: UInt16: value to be compared with the atomic type instance
  • new: UInt16: value to be written to the atomic type when the two values are equal
  • successOrder!: MemoryOrder: When the CAS operation is successful, the memory ordering required for the read > modify > write operation is executed.
  • failureOrder!: MemoryOrder: When the CAS operation fails, the memory ordering required for the read operation is executed.

Returns:

  • Bool: If the swap is successful after comparison, true is returned. Otherwise, false is returned.

func fetchAdd(UInt16)

public func fetchAdd(val: UInt16): UInt16

Description: Adds the value of an atomic type to the val parameter using the default memory ordering, writes the result to the atomic type instance, and returns the value before the addition.

Parameters:

  • val: UInt16: value to be added to the atomic type instance

Returns:

  • UInt16: value before the addition

func fetchAdd(UInt16, MemoryOrder)

public func fetchAdd(val: UInt16, memoryOrder!: MemoryOrder): UInt16

Description: Adds the value of an atomic type to the val parameter using the memory ordering specified by the memoryOrder parameter, writes the result to the atomic type instance, and returns the value before the addition.

Parameters:

  • val: UInt16: value to be added to the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • UInt16: value before the addition

func fetchAnd(UInt16)

public func fetchAnd(val: UInt16): UInt16

Description: Performs an AND operation on the value of the current atomic type instance and the val parameter using the default memory ordering, writes the result to the current atomic type instance, and returns the value before the AND operation.

Parameters:

  • val: UInt16: value to be ANDed with the atomic type instance

Returns:

  • UInt16: value before the AND operation

func fetchAnd(UInt16, MemoryOrder)

public func fetchAnd(val: UInt16, memoryOrder!: MemoryOrder): UInt16

Description: Performs an AND operation on the value of the current atomic type instance and the val parameter using the memory ordering specified by the memoryOrder parameter, writes the result to the current atomic type instance, and returns the value before the AND operation.

Parameters:

  • val: UInt16: value to be ANDed with the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • UInt16: value before the AND operation

func fetchOr(UInt16)

public func fetchOr(val: UInt16): UInt16

Description: Performs an OR operation on the value of the current atomic type instance and the val parameter using the default memory ordering, writes the result to the current atomic type instance, and returns the value before the OR operation.

Parameters:

  • val: UInt16: value to be ORed with the atomic type instance

Returns:

  • UInt16: value before the OR operation

func fetchOr(UInt16, MemoryOrder)

public func fetchOr(val: UInt16, memoryOrder!: MemoryOrder): UInt16

Description: Performs an OR operation on the value of the current atomic type instance and the val parameter using the memory ordering specified by the memoryOrder parameter, writes the result to the current atomic type instance, and returns the value before the OR operation.

Parameters:

  • val: UInt16: value to be ORed with the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • UInt16: value before the OR operation

func fetchSub(UInt16)

public func fetchSub(val: UInt16): UInt16

Description: Uses the value of an atomic type as the minuend and the val parameter as the subtrahend to perform subtraction using the default memory ordering, writes the result to the current atomic type instance, and returns the value before the subtraction.

Parameters:

  • val: UInt16: value to be subtracted from the atomic type instance

Returns:

  • UInt16: value before the subtraction

func fetchSub(UInt16, MemoryOrder)

public func fetchSub(val: UInt16, memoryOrder!: MemoryOrder): UInt16

Description: Uses the value of an atomic type as the minuend and the val parameter as the subtrahend to perform subtraction using the memory ordering specified by the memoryOrder parameter, writes the result to the current atomic type instance, and returns the value before the subtraction.

Parameters:

  • val: UInt16: value to be subtracted from the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • UInt16: value before the subtraction

func fetchXor(UInt16)

public func fetchXor(val: UInt16): UInt16

Description: Performs an XOR operation on the value of the current atomic type instance and the val parameter using the default memory ordering, writes the result to the current atomic type instance, and returns the value before the XOR operation.

Parameters:

  • val: UInt16: value to be XORed with the atomic type instance

Returns:

  • UInt16: value before the XOR operation

func fetchXor(UInt16, MemoryOrder)

public func fetchXor(val: UInt16, memoryOrder!: MemoryOrder): UInt16

Description: Performs an XOR operation on the value of the current atomic type instance and the val parameter using the memory ordering specified by the memoryOrder parameter, writes the result to the current atomic type instance, and returns the value before the XOR operation.

Parameters:

  • val: UInt16: value to be XORed with the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • UInt16: value before the XOR operation

func load()

public func load(): UInt16

Description: Reads the value of an atomic type using the default memory ordering.

Returns:

  • UInt16: value of the atomic type

func load(MemoryOrder)

public func load(memoryOrder!: MemoryOrder): UInt16

Description: Reads the value of an atomic type using the memory ordering specified by the memoryOrder parameter.

Parameters:

  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • UInt16: value of the atomic type

func store(UInt16)

public func store(val: UInt16): Unit

Description: Writes the value specified by the val parameter to an atomic type using the default memory ordering.

Parameters:

  • val: UInt16: value to be written to an atomic type

func store(UInt16, MemoryOrder)

public func store(val: UInt16, memoryOrder!: MemoryOrder): Unit

Description: Writes the value specified by the val parameter to an atomic type using the memory ordering specified by the memoryOrder parameter.

Parameters:

  • val: UInt16: value to be written to an atomic type
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

func swap(UInt16)

public func swap(val: UInt16): UInt16

Description: Performs a swap operation to write the value specified by the val parameter to an atomic type using the default memory ordering, and returns the value before the writing.

Parameters:

  • val: UInt16: value to be written to an atomic type

Returns:

  • UInt16: value before writing

func swap(UInt16, MemoryOrder)

public func swap(val: UInt16, memoryOrder!: MemoryOrder): UInt16

Description: Performs a swap operation to write the value specified by the val parameter to an atomic type using the memory ordering specified by the memoryOrder parameter, and returns the value before the writing.

Parameters:

  • val: UInt16: value to be written to an atomic type
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • UInt16: value before writing

class AtomicUInt32

public class AtomicUInt32

Description: Provides functions related to atomic operations of the UInt32 class.

init(UInt32)

public init(val: UInt32)

Description: Constructs an instance of the atomic type AtomicUInt32 that encapsulates the data type UInt32. The initial value of the internal data for the instance is the value of the input parameter val.

Parameters:

  • val: UInt32: initial value of the atomic type

func compareAndSwap(UInt32, UInt32)

public func compareAndSwap(old: UInt32, new: UInt32): Bool

Description: Performs a CAS operation using the default memory ordering.

The value of the atomic type and the value specified by the old parameter are compared for equality. If they are equal, the value specified by the new parameter is written and true is returned. Otherwise, no value is written and false is returned.

Parameters:

  • old: UInt32: value to be compared with the atomic type instance
  • new: UInt32: value to be written to the atomic type when the two values are equal

Returns:

  • Bool: If the swap is successful after comparison, true is returned. Otherwise, false is returned.

func compareAndSwap(UInt32, UInt32, MemoryOrder, MemoryOrder)

public func compareAndSwap(old: UInt32, new: UInt32, successOrder!: MemoryOrder, failureOrder!: MemoryOrder): Bool

Description: Performs a CAS operation using the memory ordering specified by successOrder used upon success and the memory ordering specified by failureOrder used upon failure.

The value of the atomic type and the value specified by the old parameter are compared for equality. If they are equal, the value specified by the new parameter is written and true is returned. Otherwise, no value is written and false is returned.

Parameters:

  • old: UInt32: value to be compared with the atomic type instance
  • new: UInt32: value to be written to the atomic type when the two values are equal
  • successOrder!: MemoryOrder: When the CAS operation is successful, the memory ordering required for the read > modify > write operation is executed.
  • failureOrder!: MemoryOrder: When the CAS operation fails, the memory ordering required for the read operation is executed.

Returns:

  • Bool: If the swap is successful after comparison, true is returned. Otherwise, false is returned.

func fetchAdd(UInt32)

public func fetchAdd(val: UInt32): UInt32

Description: Adds the value of an atomic type to the val parameter using the default memory ordering, writes the result to the atomic type instance, and returns the value before the addition.

Parameters:

  • val: UInt32: value to be added to the atomic type instance

Returns:

  • UInt32: value before the addition

func fetchAdd(UInt32, MemoryOrder)

public func fetchAdd(val: UInt32, memoryOrder!: MemoryOrder): UInt32

Description: Adds the value of an atomic type to the val parameter using the memory ordering specified by the memoryOrder parameter, writes the result to the atomic type instance, and returns the value before the addition.

Parameters:

  • val: UInt32: value to be added to the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • UInt32: value before the addition

func fetchAnd(UInt32)

public func fetchAnd(val: UInt32): UInt32

Description: Performs an AND operation on the value of the current atomic type instance and the val parameter using the default memory ordering, writes the result to the current atomic type instance, and returns the value before the AND operation.

Parameters:

  • val: UInt32: value to be ANDed with the atomic type instance

Returns:

  • UInt32: value before the AND operation

func fetchAnd(UInt32, MemoryOrder)

public func fetchAnd(val: UInt32, memoryOrder!: MemoryOrder): UInt32

Description: Performs an AND operation on the value of the current atomic type instance and the val parameter using the memory ordering specified by the memoryOrder parameter, writes the result to the current atomic type instance, and returns the value before the AND operation.

Parameters:

  • val: UInt32: value to be ANDed with the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • UInt32: value before the AND operation

func fetchOr(UInt32)

public func fetchOr(val: UInt32): UInt32

Description: Performs an OR operation on the value of the current atomic type instance and the val parameter with the default memory ordering, writes the result to the current atomic type instance, and returns the value before the OR operation.

Parameters:

  • val: UInt32: value to be ORed with the atomic type instance

Returns:

  • UInt32: value before the OR operation

func fetchOr(UInt32, MemoryOrder)

public func fetchOr(val: UInt32, memoryOrder!: MemoryOrder): UInt32

Description: Performs an OR operation on the value of the current atomic type instance and the val parameter using the memory ordering specified by the memoryOrder parameter, writes the result to the current atomic type instance, and returns the value before the OR operation.

Parameters:

  • val: UInt32: value to be ORed with the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • UInt32: value before the OR operation

func fetchSub(UInt32)

public func fetchSub(val: UInt32): UInt32

Description: Uses the value of an atomic type as the minuend and the val parameter as the subtrahend to perform subtraction using the default memory ordering, writes the result to the current atomic type instance, and returns the value before the subtraction.

Parameters:

  • val: UInt32: value to be subtracted from the atomic type instance

Returns:

  • UInt32: value before the subtraction

func fetchSub(UInt32, MemoryOrder)

public func fetchSub(val: UInt32, memoryOrder!: MemoryOrder): UInt32

Description: Uses the value of an atomic type as the minuend and the val parameter as the subtrahend to perform subtraction using the memory ordering specified by the memoryOrder parameter, writes the result to the current atomic type instance, and returns the value before the subtraction.

Parameters:

  • val: UInt32: value to be subtracted from the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • UInt32: value before the subtraction

func fetchXor(UInt32)

public func fetchXor(val: UInt32): UInt32

Description: Performs an XOR operation on the value of the current atomic type instance and the val parameter using the default memory ordering, writes the result to the current atomic type instance, and returns the value before the XOR operation.

Parameters:

  • val: UInt32: value to be XORed with the atomic type instance

Returns:

  • UInt32: value before the XOR operation

func fetchXor(UInt32, MemoryOrder)

public func fetchXor(val: UInt32, memoryOrder!: MemoryOrder): UInt32

Description: Performs an XOR operation on the value of the current atomic type instance and the val parameter using the memory ordering specified by the memoryOrder parameter, writes the result to the current atomic type instance, and returns the value before the XOR operation.

Parameters:

  • val: UInt32: value to be XORed with the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • UInt32: value before the XOR operation

func load()

public func load(): UInt32

Description: Reads the value of an atomic type using the default memory ordering.

Returns:

  • UInt32: value of the atomic type

func load(MemoryOrder)

public func load(memoryOrder!: MemoryOrder): UInt32

Description: Reads the value of an atomic type using the memory ordering specified by the memoryOrder parameter.

Parameters:

  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • UInt32: value of the atomic type

func store(UInt32)

public func store(val: UInt32): Unit

Description: Writes the value specified by the val parameter to an atomic type using the default memory ordering.

Parameters:

  • val: UInt32: value to be written to an atomic type

func store(UInt32, MemoryOrder)

public func store(val: UInt32, memoryOrder!: MemoryOrder): Unit

Description: Writes the value specified by the val parameter to an atomic type using the memory ordering specified by the memoryOrder parameter.

Parameters:

  • val: UInt32: value to be written to an atomic type
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

func swap(UInt32)

public func swap(val: UInt32): UInt32

Description: Performs a swap operation using the default memory ordering to write the value specified by the val parameter to an atomic type, and returns the value before the writing.

Parameters:

  • val: UInt32: value to be written to an atomic type

Returns:

  • UInt32: value before writing

func swap(UInt32, MemoryOrder)

public func swap(val: UInt32, memoryOrder!: MemoryOrder): UInt32

Description: Performs a swap operation to write the value specified by the val parameter to an atomic type using the memory ordering specified by the memoryOrder parameter, and returns the value before the writing.

Parameters:

  • val: UInt32: value to be written to an atomic type
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • UInt32: value before writing

class AtomicUInt64

public class AtomicUInt64

Description: Provides functions related to atomic operations of the UInt64 class.

init(UInt64)

public init(val: UInt64)

Description: Constructs an instance of the atomic type AtomicUInt64 that encapsulates the data type UInt64. The initial value of the internal data for the instance is the value of the input parameter val.

Parameters:

  • val: UInt64: initial value of the atomic type

func compareAndSwap(UInt64, UInt64)

public func compareAndSwap(old: UInt64, new: UInt64): Bool

Description: Performs a CAS operation using the default memory ordering.

The value of the atomic type and the value specified by the old parameter are compared for equality. If they are equal, the value specified by the new parameter is written and true is returned. Otherwise, no value is written and false is returned.

Parameters:

  • old: UInt64: value to be compared with the atomic type instance
  • new: UInt64: value to be written to the atomic type when the two values are equal

Returns:

  • Bool: If the swap is successful after comparison, true is returned. Otherwise, false is returned.

func compareAndSwap(UInt64, UInt64, MemoryOrder, MemoryOrder)

public func compareAndSwap(old: UInt64, new: UInt64, successOrder!: MemoryOrder, failureOrder!: MemoryOrder): Bool

Description: Performs a CAS operation using the memory ordering specified by successOrder used upon success and the memory ordering specified by failureOrder used upon failure.

The value of the atomic type and the value specified by the old parameter are compared for equality. If they are equal, the value specified by the new parameter is written and true is returned. Otherwise, no value is written and false is returned.

Parameters:

  • old: UInt64: value to be compared with the atomic type instance
  • new: UInt64: value to be written to the atomic type when the two values are equal
  • successOrder!: MemoryOrder: When the CAS operation is successful, the memory ordering required for the read > modify > write operation is executed.
  • failureOrder!: MemoryOrder: When the CAS operation fails, the memory ordering required for the read operation is executed.

Returns:

  • Bool: If the swap is successful after comparison, true is returned. Otherwise, false is returned.

func fetchAdd(UInt64)

public func fetchAdd(val: UInt64): UInt64

Description: Adds the value of an atomic type to the val parameter using the default memory ordering, writes the result to the atomic type instance, and returns the value before the addition.

Parameters:

  • val: UInt64: value to be added to the atomic type instance

Returns:

  • UInt64: value before the addition

func fetchAdd(UInt64, MemoryOrder)

public func fetchAdd(val: UInt64, memoryOrder!: MemoryOrder): UInt64

Description: Adds the value of an atomic type to the val parameter using the memory ordering specified by the memoryOrder parameter, writes the result to the atomic type instance, and returns the value before the addition.

Parameters:

  • val: UInt64: value to be added to the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • UInt64: value before the addition

func fetchAnd(UInt64)

public func fetchAnd(val: UInt64): UInt64

Description: Performs an AND operation on the value of the current atomic type instance and the val parameter using the default memory ordering, writes the result to the current atomic type instance, and returns the value before the AND operation.

Parameters:

  • val: UInt64: value to be ANDed with the atomic type instance

Returns:

  • UInt64: value before the AND operation

func fetchAnd(UInt64, MemoryOrder)

public func fetchAnd(val: UInt64, memoryOrder!: MemoryOrder): UInt64

Description: Performs an AND operation on the value of the current atomic type instance and the val parameter using the memory ordering specified by the memoryOrder parameter, writes the result to the current atomic type instance, and returns the value before the AND operation.

Parameters:

  • val: UInt64: value to be ANDed with the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • UInt64: value before the AND operation

func fetchOr(UInt64)

public func fetchOr(val: UInt64): UInt64

Description: Performs an OR operation on the value of the current atomic type instance and the val parameter using the default memory ordering, writes the result to the current atomic type instance, and returns the value before the OR operation.

Parameters:

  • val: UInt64: value to be ORed with the atomic type instance

Returns:

  • UInt64: value before the OR operation

func fetchOr(UInt64, MemoryOrder)

public func fetchOr(val: UInt64, memoryOrder!: MemoryOrder): UInt64

Description: Performs an OR operation on the value of the current atomic type instance and the val parameter using the memory ordering specified by the memoryOrder parameter, writes the result to the current atomic type instance, and returns the value before the OR operation.

Parameters:

  • val: UInt64: value to be ORed with the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • UInt64: value before the OR operation

func fetchSub(UInt64)

public func fetchSub(val: UInt64): UInt64

Description: Uses the value of an atomic type as the minuend and the val parameter as the subtrahend to perform subtraction using the default memory ordering, writes the result to the current atomic type instance, and returns the value before the subtraction.

Parameters:

  • val: UInt64: value to be subtracted from the atomic type instance

Returns:

  • UInt64: value before the subtraction

func fetchSub(UInt64, MemoryOrder)

public func fetchSub(val: UInt64, memoryOrder!: MemoryOrder): UInt64

Description: Uses the value of an atomic type as the minuend and the val parameter as the subtrahend to perform subtraction using the memory ordering specified by the memoryOrder parameter, writes the result to the current atomic type instance, and returns the value before the subtraction.

Parameters:

  • val: UInt64: value to be subtracted from the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • UInt64: value before the subtraction

func fetchXor(UInt64)

public func fetchXor(val: UInt64): UInt64

Description: Performs an XOR operation on the value of the current atomic type instance and the val parameter using the default memory ordering, writes the result to the current atomic type instance, and returns the value before the XOR operation.

Parameters:

  • val: UInt64: value to be XORed with the atomic type instance

Returns:

  • UInt64: value before the XOR operation

func fetchXor(UInt64, MemoryOrder)

public func fetchXor(val: UInt64, memoryOrder!: MemoryOrder): UInt64

Description: Performs an XOR operation on the value of the current atomic type instance and the val parameter using the memory ordering specified by the memoryOrder parameter, writes the result to the current atomic type instance, and returns the value before the XOR operation.

Parameters:

  • val: UInt64: value to be XORed with the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • UInt64: value before the XOR operation

func load()

public func load(): UInt64

Description: Reads the value of an atomic type using the default memory ordering.

Returns:

  • UInt64: value of the atomic type

func load(MemoryOrder)

public func load(memoryOrder!: MemoryOrder): UInt64

Description: Reads the value of an atomic type using the memory ordering specified by the memoryOrder parameter.

Parameters:

  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • UInt64: value of the atomic type

func store(UInt64)

public func store(val: UInt64): Unit

Description: Writes the value specified by the val parameter to an atomic type using the default memory ordering.

Parameters:

  • val: UInt64: value to be written to an atomic type

func store(UInt64, MemoryOrder)

public func store(val: UInt64, memoryOrder!: MemoryOrder): Unit

Description: Writes the value specified by the val parameter to an atomic type using the memory ordering specified by the memoryOrder parameter.

Parameters:

  • val: UInt64: value to be written to an atomic type
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

func swap(UInt64)

public func swap(val: UInt64): UInt64

Description: Performs a swap operation to write the value specified by the val parameter to an atomic type using the default memory ordering, and returns the value before the writing.

Parameters:

  • val: UInt64: value to be written to an atomic type

Returns:

  • UInt64: value before writing

func swap(UInt64, MemoryOrder)

public func swap(val: UInt64, memoryOrder!: MemoryOrder): UInt64

Description: Performs a swap operation to write the value specified by the val parameter to an atomic type using the memory ordering specified by the memoryOrder parameter, and returns the value before the writing.

Parameters:

  • val: UInt64: value to be written to an atomic type
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • UInt64: value before writing

class AtomicUInt8

public class AtomicUInt8

Description: Provides functions related to atomic operations of the UInt8 class.

init(UInt8)

public init(val: UInt8)

Description: Constructs an instance of the atomic type AtomicUInt8 that encapsulates the data type UInt8. The initial value of the internal data for the instance is the value of the input parameter val.

Parameters:

  • val: UInt8: initial value of the atomic type

func compareAndSwap(UInt8, UInt8)

public func compareAndSwap(old: UInt8, new: UInt8): Bool

Description: Performs a CAS operation using the default memory ordering.

The value of the atomic type and the value specified by the old parameter are compared for equality. If they are equal, the value specified by the new parameter is written and true is returned. Otherwise, no value is written and false is returned.

Parameters:

  • old: UInt8: value to be compared with the atomic type instance
  • new: UInt8: value to be written to the atomic type when the two values are equal

Returns:

  • Bool: If the swap is successful after comparison, true is returned. Otherwise, false is returned.

func compareAndSwap(UInt8, UInt8, MemoryOrder, MemoryOrder)

public func compareAndSwap(old: UInt8, new: UInt8, successOrder!: MemoryOrder, failureOrder!: MemoryOrder): Bool

Description: Performs a CAS operation using the memory ordering specified by successOrder used upon success and the memory ordering specified by failureOrder used upon failure.

The value of the atomic type and the value specified by the old parameter are compared for equality. If they are equal, the value specified by the new parameter is written and true is returned. Otherwise, no value is written and false is returned.

Parameters:

  • old: UInt8: value to be compared with the atomic type instance
  • new: UInt8: value to be written to the atomic type when the two values are equal
  • successOrder!: MemoryOrder: When the CAS operation is successful, the memory ordering required for the read > modify > write operation is executed.
  • failureOrder!: MemoryOrder: When the CAS operation fails, the memory ordering required for the read operation is executed.

Returns:

  • Bool: If the swap is successful after comparison, true is returned. Otherwise, false is returned.

func fetchAdd(UInt8)

public func fetchAdd(val: UInt8): UInt8

Description: Adds the value of an atomic type to the val parameter using the default memory ordering, writes the result to the atomic type instance, and returns the value before the addition.

Parameters:

  • val: UInt8: value to be added to the atomic type instance

Returns:

  • UInt8: value before the addition

func fetchAdd(UInt8, MemoryOrder)

public func fetchAdd(val: UInt8, memoryOrder!: MemoryOrder): UInt8

Description: Adds the value of an atomic type to the val parameter using the memory ordering specified by the memoryOrder parameter, writes the result to the atomic type instance, and returns the value before the addition.

Parameters:

  • val: UInt8: value to be added to the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • UInt8: value before the addition

func fetchAnd(UInt8)

public func fetchAnd(val: UInt8): UInt8

Description: Performs an AND operation on the value of the current atomic type instance and the val parameter using the default memory ordering, writes the result to the current atomic type instance, and returns the value before the AND operation.

Parameters:

  • val: UInt8: value to be ANDed with the atomic type instance

Returns:

  • UInt8: value before the AND operation

func fetchAnd(UInt8, MemoryOrder)

public func fetchAnd(val: UInt8, memoryOrder!: MemoryOrder): UInt8

Description: Performs an AND operation on the value of the current atomic type instance and the val parameter using the memory ordering specified by the memoryOrder parameter, writes the result to the current atomic type instance, and returns the value before the AND operation.

Parameters:

  • val: UInt8: value to be ANDed with the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • UInt8: value before the AND operation

func fetchOr(UInt8)

public func fetchOr(val: UInt8): UInt8

Description: Performs an OR operation on the value of the current atomic type instance and the val parameter using the default memory ordering, writes the result to the current atomic type instance, and returns the value before the OR operation.

Parameters:

  • val: UInt8: value to be ORed with the atomic type instance

Returns:

  • UInt8: value before the OR operation

func fetchOr(UInt8, MemoryOrder)

public func fetchOr(val: UInt8, memoryOrder!: MemoryOrder): UInt8

Description: Performs an OR operation on the value of the current atomic type instance and the val parameter using the memory ordering specified by the memoryOrder parameter, writes the result to the current atomic type instance, and returns the value before the OR operation.

Parameters:

  • val: UInt8: value to be ORed with the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • UInt8: value before the OR operation

func fetchSub(UInt8)

public func fetchSub(val: UInt8): UInt8

Description: Uses the value of an atomic type as the minuend and the val parameter as the subtrahend to perform subtraction using the default memory ordering, writes the result to the current atomic type instance, and returns the value before the subtraction.

Parameters:

  • val: UInt8: value to be subtracted from the atomic type instance

Returns:

  • UInt8: value before the subtraction

func fetchSub(UInt8, MemoryOrder)

public func fetchSub(val: UInt8, memoryOrder!: MemoryOrder): UInt8

Description: Uses the value of an atomic type as the minuend and the val parameter as the subtrahend to perform subtraction using the memory ordering specified by the memoryOrder parameter, writes the result to the current atomic type instance, and returns the value before the subtraction.

Parameters:

  • val: UInt8: value to be subtracted from the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • UInt8: value before the subtraction

func fetchXor(UInt8)

public func fetchXor(val: UInt8): UInt8

Description: Performs an XOR operation on the value of the current atomic type instance and the val parameter using the default memory ordering, writes the result to the current atomic type instance, and returns the value before the XOR operation.

Parameters:

  • val: UInt8: value to be XORed with the atomic type instance

Returns:

  • UInt8: value before the XOR operation

func fetchXor(UInt8, MemoryOrder)

public func fetchXor(val: UInt8, memoryOrder!: MemoryOrder): UInt8

Description: Performs an XOR operation on the value of the current atomic type instance and the val parameter using the memory ordering specified by the memoryOrder parameter, writes the result to the current atomic type instance, and returns the value before the XOR operation.

Parameters:

  • val: UInt8: value to be XORed with the atomic type instance
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • UInt8: value before the XOR operation

func load()

public func load(): UInt8

Description: Reads the value of an atomic type using the default memory ordering.

Returns:

  • UInt8: value of the atomic type

func load(MemoryOrder)

public func load(memoryOrder!: MemoryOrder): UInt8

Description: Reads the value of an atomic type using the memory ordering specified by the memoryOrder parameter.

Parameters:

  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • UInt8: value of the atomic type

func store(UInt8)

public func store(val: UInt8): Unit

Description: Writes the value specified by the val parameter to an atomic type using the default memory ordering.

Parameters:

  • val: UInt8: value to be written to an atomic type

func store(UInt8, MemoryOrder)

public func store(val: UInt8, memoryOrder!: MemoryOrder): Unit

Description: Writes the value specified by the val parameter to an atomic type using the memory ordering specified by the memoryOrder parameter.

Parameters:

  • val: UInt8: value to be written to an atomic type
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

func swap(UInt8)

public func swap(val: UInt8): UInt8

Description: Performs a swap operation to write the value specified by the val parameter to an atomic type using the default memory ordering, and returns the value before the writing.

Parameters:

  • val: UInt8: value to be written to an atomic type

Returns:

  • UInt8: value before writing

func swap(UInt8, MemoryOrder)

public func swap(val: UInt8, memoryOrder!: MemoryOrder): UInt8

Description: Performs a swap operation to write the value specified by the val parameter to an atomic type using the memory ordering specified by the memoryOrder parameter, and returns the value before the writing.

Parameters:

  • val: UInt8: value to be written to an atomic type
  • memoryOrder!: MemoryOrder: memory ordering of the current operation

Returns:

  • UInt8: value before writing

class Barrier

public class Barrier

Description: Provides the function of coordinating the execution of multiple threads to a program point.

Threads reaching the program point enter the blocked status until all threads reach the program point to continue the execution.

init(Int64)

public init(count: Int64)

Description: Creates a Barrier object.

Parameters:

  • count: Int64: number of threads to be coordinated.

Throws:

func wait(Duration)

public func wait(timeout!: Duration = Duration.Max): Unit

Description: Instructs a thread to enter the Barrier waiting point.

If the number of times (the number of threads entering the waiting point) the Barrier object calls the wait method equals the initial value, all waiting threads are woken up. If the number of times the wait method is called is less than the initial value, the current thread enters the blocked status until it is woken up or the waiting time exceeds timeout. If the number of times the wait method is called is greater than the initial value, the thread continues running.

Parameters:

class Monitor

public class Monitor <: ReentrantMutex

Description: Provides the function of blocking a thread and waiting for a signal from another thread to resume execution.

This is a mechanism that uses shared variables to synchronize threads. Specifically, if some threads are suspended when waiting for certain condition satisfaction of the shared variables, other threads change the shared variables for the condition to be met. Then, the suspended threads are woken up to continue running.

Parent Type:

init()

public init()

Description: Creates a Monitor object instance using the default constructor.

func notify()

public func notify(): Unit

Function: Wakes up a thread waiting on the Montior.

Throws:

func notifyAll()

public func notifyAll(): Unit

Description: Wakes up all threads waiting on the Montior.

Throws:

func wait(Duration)

public func wait(timeout!: Duration = Duration.Max): Bool

Description: Instructs the current thread to be suspended until the corresponding notify function is called or the suspension duration exceeds timeout.

Parameters:

Returns:

  • Bool: If Monitor is woken up by another thread, true is returned. If timeout occurs, false is returned.

Throws:

class MultiConditionMonitor

public class MultiConditionMonitor <: ReentrantMutex

Description: Provides the function of binding multiple condition variables to the same mutex.

Note:

  • This class should be used only when the Monitor class cannot implement advanced concurrency algorithms.
  • During initialization, there is no condition variable related to MultiConditionMonitor.
  • Each time newCondition is called, a new waiting queue is created and associated with the current object, and an instance of the ConditionID type is returned as the unique identifier.

Parent Type:

init()

public init()

Description: Creates a MultiConditionMonitor object instance using the default constructor.

func newCondition()

public func newCondition(): ConditionID

Description: Creates ConditionID related to Monitor, which may be used to implement the concurrency primitive of "single mutex for multiple waiting queues".

Returns:

Throws:

func notify(ConditionID)

public func notify(condID: ConditionID): Unit

Description: Wakes up a thread (if any) waiting for the specified condition variable.

Parameters:

Throws:

func notifyAll(ConditionID)

public func notifyAll(condID: ConditionID): Unit

Description: Wakes up all threads (if any) waiting for the specified condition variable.

Parameters:

Throws:

func wait(ConditionID, Duration)

public func wait(condID: ConditionID, timeout!: Duration = Duration.Max): Bool

Description: Instructs the current thread to be suspended until the corresponding notify function is called.

Parameters:

Returns:

  • Bool: If the condition variable specified by Monitor is woken up by another thread, true is returned. If timeout occurs, false is returned.

Throws:

class ReentrantMutex

public open class ReentrantMutex <: IReentrantMutex

Description: Provides functions related to reentrant mutexes.

The function of a reentrant mutex is to protect the critical section so that only one thread can execute the code in the critical section at any time. When a thread attempts to obtain a mutex that has been held by another thread, the thread is blocked and is not woken up until the mutex is released. The word reentrant indicates that a thread can obtain a mutex again after obtaining it.

Note:

  • ReentrantMutex provides built-in mutexes. Developers must ensure that no classes inherit it?
  • Before shared data is accessed, a mutex must be obtained.
  • After the shared data is processed, the mutex must be unlocked for other threads to obtain.

Parent Type:

init()

public init()

Description: Creates a reentrant mutex.

Throws:

func lock()

public open func lock(): Unit

Description: Locks a mutex. If the mutex has been locked, the blocked status is entered.

func tryLock()

public open func tryLock(): Bool

Description: Attempts to lock a mutex.

Returns:

  • Bool: If the mutex has been locked, false is returned. Otherwise, the mutex is locked and true is returned.

func unlock

public open func unlock(): Unit

Description: Unlocks a mutex.

If the mutex is locked for N times, this function needs to be called for N times to completely unlock the mutex. Once the mutex is completely unlocked, one of other threads blocked and waiting for the mutex is woken up.

Throws:

class ReentrantReadMutex

public class ReentrantReadMutex <: ReentrantMutex

Description: Specifies the read lock class in reentrant read-write locks.

Parent Type:

func lock()

public func lock(): Unit

Description: Obtains a read lock.

Note:

  • In fair mode, if no other thread holds or is waiting for the write lock, or the current thread has held the read lock, the current thread holds the read lock immediately. Otherwise, the current thread enters the waiting status.
  • In unfair mode, if no other thread holds or is waiting for the write lock, the current thread holds the read lock immediately. If another thread holds the write lock, the current thread enters the waiting status. Otherwise, whether the thread can hold the read lock immediately is not guaranteed.
  • Multiple threads can hold the read lock concurrently, and one thread can hold the read lock repeatedly. A thread holding the write lock, can still hold the read lock.

func tryLock()

public func tryLock(): Bool

Description: Attempts to obtain a read lock. This method does not follow the fair mode when used to obtain a read lock.

Returns:

  • Bool: If the read lock is successfully obtained, true is returned. If the read lock is not obtained, false is returned.

func unlock()

public func unlock(): Unit

Description: Releases a read lock. If a thread holds the read lock repeatedly, the read lock is released only when the number of release operations is equal to that of obtain operations. After the read lock is released, one of the threads waiting for the write lock is woken up.

Throws:

class ReentrantReadWriteMutex

public class ReentrantReadWriteMutex

Description: Provides functions related to reentrant read-write locks.

Difference between a read-write lock and a common mutex: A read-write lock carries two mutexes, a read lock and a write lock, and allows multiple threads to hold the read lock concurrently.

Special properties of a read-write lock:

  • Mutual exclusivity of writing: Only one thread can hold the write lock. When a thread holds the write lock, another thread is blocked when attempting to obtain a lock (read lock or write lock).
  • Read concurrency: Multiple threads are allowed to hold the read lock concurrently. When a thread holds the read lock, other threads can still obtain the read lock. However, other threads are blocked when attempting to obtain the write lock.
  • Reentrance: A thread can obtain a lock repeatedly.
    • A thread holding the write lock can still obtain the write lock or read lock. A lock is completely released only when the lock release and obtain operations are in a one-to-one correspondence.
    • A thread holding the read lock can obtain the read lock again. A lock is completely released only when the lock release and obtain operations are in a one-to-one correspondence. Note: Obtaining the write lock when the read lock is held is not allowed and triggers an exception.
  • Lock degradation: After holding the write lock > holding the read lock > releasing the write lock, a thread holds the read lock instead of the write lock.
  • Read/write fairness: A read-write lock supports fair and unfair modes.
    • In unfair mode, the sequence of obtaining locks by threads is not guaranteed for a read-write lock.
    • In fair mode, when a thread obtains the read lock (the current thread does not hold the read lock), if the write lock has been obtained or any thread is waiting for the write lock, the current thread cannot obtain the read lock and enters the waiting status.
    • In fair mode, when the write lock is released, all read threads are woken up preferentially. When the read lock is released, a thread waiting for the write lock is woken up preferentially. The sequence of waking up multiple threads waiting for the write lock is not guaranteed.

prop readMutex

public prop readMutex: ReentrantReadMutex

Description: Obtains a read lock.

Type: ReentrantReadMutex

prop writeMutex

public prop writeMutex: ReentrantWriteMutex

Description: Obtains a write lock.

Type: ReentrantWriteMutex

init(ReadWriteMutexMode)

public init(mode!: ReadWriteMutexMode = ReadWriteMutexMode.Unfair)

Description: Constructs a read-write lock.

Parameters:

  • mode!: ReadWriteMutexMode: read-write lock mode; default value: Unfair, indicating that a read-write lock in unfair mode is to be constructed

class ReentrantWriteMutex

public class ReentrantWriteMutex <: ReentrantMutex

Description: Specifies the write lock class in reentrant read-write locks.

Parent Type:

func lock()

public func lock(): Unit

Description: Obtains a write lock. Only one thread is allowed to hold the write lock at the same time, and a thread can hold the write lock repeatedly. If another thread holds the write lock or read lock, the current thread enters the waiting status.

Throws:

func tryLock()

public func tryLock(): Bool

Description: Attempts to obtain a write lock. This method does not follow the fair mode when used to obtain a read lock.

Returns:

  • Bool: If the write lock is successfully obtained, true is returned. If the read lock is not obtained, false is returned.

func unlock()

public func unlock(): Unit

Description: Releases a write lock.

Note:

  • If a thread holds the read lock repeatedly, the read lock is released only when the number of release operations is equal to that of obtain operations. After the read lock is released, one of the threads waiting for the write lock is woken up.
  • In fair mode, if the write lock is released, threads waiting for the read lock are woken up preferentially. If no thread is waiting for the read lock, one of threads waiting for the write lock is woken up.
  • In unfair mode, if the write lock is released, whether a thread waiting for the write lock or a thread waiting for the read lock is preferentially woken up is determined by specific implementation.

Throws:

class Semaphore

public class Semaphore

Description: Provides functions related to semaphores.

A Semaphore can be considered as a Monitor carrying a counter and is often used to control the number of threads concurrently accessing shared resources.

prop count

public prop count: Int64

Description: Returns the value of the current internal counter.

Type: Int64

init(Int64)

public init(count: Int64)

Description: Creates a Semaphore object and initializes the value of the internal counter.

Parameters:

Throws:

func acquire(Int64)

public func acquire(amount!: Int64 = 1): Unit

Description: Obtains a specified value from the Semaphore object.

If the current counter is less than the required value, the current thread is blocked and is not woken up until the value that meets the requirement is obtained.

Parameters:

  • amount!: Int64: value to be obtained from the internal counter of the object; default value: 1

Throws:

  • IllegalArgumentException: When the value of the amount parameter is negative or greater than the initial value, this exception is thrown.

func release(Int64)

public func release(amount!: Int64 = 1): Unit

Description: Releases a specified value to the Semaphore object.

If the internal counter can meet the requirements of the thread that is currently blocked at the Semaphore object after the released values are accumulated, the thread is woken up. The value of the internal counter is not greater than the initial value. That is, if the value of the internal counter is greater than the initial value after the accumulation, the value is set to the initial value. All operations before release is called occur before operations after acquire/tryAcquire is called.

Parameters:

  • amount!: Int64: value to be released to the internal counter of the object; default value: 1

Returns:

  • Unit: If the value of the current counter is less than the required value, the obtaining fails and false is returned. If the obtaining is successful, true is returned.

Throws:

  • IllegalArgumentException: When the value of the amount parameter is negative or greater than the initial value, this exception is thrown.

func tryAcquire(Int64)

public func tryAcquire(amount!: Int64 = 1): Bool

Description: Attempts to obtain a specified value from the Semaphore object.

This method does not block threads. If multiple threads concurrently perform the obtain operation, the obtaining sequence is not guaranteed.

Parameters:

  • amount!: Int64: value to be obtained from the internal counter of the object; default value: 1

Returns:

  • Bool: If the value of the current counter is less than the required value, the obtaining fails and false is returned. If the obtaining is successful, true is returned.

Throws:

  • IllegalArgumentException: When the value of the amount parameter is negative or greater than the initial value, this exception is thrown.

class SyncCounter

public class SyncCounter

Description: Provides countdown counter functions.

Threads can wait for the value of the counter to become zero.

prop count

public prop count: Int64

Description: Obtains the current value of the counter.

Type: Int64

init(Int64)

public init(count: Int64)

Description: Creates a countdown counter.

Parameters:

  • count: Int64: initial value of the countdown counter

Throws:

func dec()

public func dec(): Unit

Description: Decreases the value of the counter by one.

If the value of the counter becomes zero, all waiting threads are woken up. If the value of the counter is already zero, the value remains unchanged.

func waitUntilZero(Duration)

public func waitUntilZero(timeout!: Duration = Duration.Max): Unit

Description: Instructs the current thread to wait until the value of the counter becomes zero or the waiting duration exceeds timeout.

Parameters:

class Timer

public class Timer <: Equatable<Timer> & Hashable

Description: Provides timer functions.

This class is used to execute a specified task once or multiple times at a specified time point or after a specified interval.

Note:

  • Timer implicitly includes the spawn operation. That is, each Timer creates a thread to execute its associated task.
  • Each Timer can be bound to one task only during initialization. After the initialization is complete, the associated task cannot be reset.
  • The lifecycle of Timer ends only after the associated task is executed or the cancel interface is used to cancel Timer. Then, Timer can be reclaimed by GC. In other words, before the task associated with Timer is executed or Timer is canceled, Timer instance is not reclaimed by GC. This ensures that the associated task can be properly executed.
  • When the system is busy, the triggering time of the task may be affected. Timer does not guarantee on-time task triggering, but ensures that the triggering time of the task is earlier than or the same as the current time.
  • Timer does not proactively capture exceptions thrown from the associated task. If any exception of the task is not captured, Timer becomes invalid.
  • Timer includes one-off task timers and repetitive task timers based on the usage method. When a one-off task timer is used, the task is executed only once. When a repetitive task timer is used, the task is executed periodically as specified until the cancel interface is used to cancel the task or the end condition specified upon creation of Timer is met.

Parent Type:

static func after(Duration, ()->?Duration)

public static func after(delay: Duration, task: () -> Option<Duration>): Timer

Description: Initializes a Timer. The number of times the associated task is scheduled for execution depends on the return value. If the time when the timer is triggered for the first time is earlier than the current time, the associated task is scheduled for execution immediately. If the return value of the associated task is Option.None, Timer becomes invalid and the associated task stops being scheduled. If the return value of the associated task is Option.Some(v) and v is greater than Duration.Zero, the minimum interval before the next running is set to v. Otherwise, the associated task is scheduled for execution again immediately.

Parameters:

  • delay: Duration: interval between the current time and the time when the associated task is scheduled for execution for the first time
  • task: () ->Option<Duration>: task to be scheduled for execution by Timer

Returns:

static func once(Duration, ()->Unit)

public static func once(delay: Duration, task: ()->Unit): Timer

Description: Sets and starts a one-off scheduled task, and returns the Timer object instance that controls the task.

Parameters:

  • delay: interval between the current time and the time when the task is executed; value range: [Duration.Min, Duration.Max]. If the value is less than or equal to Duration.Zero, the task is executed immediately.
  • task: task to be executed as scheduled

Returns: Timer object instance

Example:

import std.sync.{Timer, sleep}
import std.time.{Duration, MonoTime}

main() {
    let start = MonoTime.now()
    Timer.once(Duration.second, {=>
        println("Tick at: ${MonoTime.now() - start}")
    })

    sleep(Duration.second * 2)
    0
}

Running result:

Tick at: 1s2ms74us551ns

static func repeat(Duration, Duration, ()->Unit, CatchupStyle)

public static func repeat(delay: Duration, interval: Duration, task: ()->Unit, style!: CatchupStyle = Burst): Timer

Description: Sets and starts a one-off repetitive task, and returns the Timer object instance that controls the task.

Parameters:

  • delay: interval between the current time and the time when the task is executed; value range: [Duration.Min, Duration.Max]. If the value is less than or equal to Duration.Zero, the task is executed immediately.
  • interval: interval between two task executions; value range: (Duration.Zero, Duration.Max]
  • task: task to be executed as scheduled
  • style: catch-up policy; default value: Burst. If the execution duration of a task is too long, the execution times of subsequent tasks may be delayed. Different catch-up policies apply to different scenarios. For details, see CatchupStyle description.

Returns: Timer object instance

Throws:

Example:

import std.sync.{Timer, sleep}
import std.time.{Duration, MonoTime}

main() {
    let start = MonoTime.now()
    let timer = Timer.repeat(Duration.second, Duration.second, {=>
        println("Tick at: ${MonoTime.now() - start}")
    })


    sleep(Duration.second * 5)
    timer.cancel()

    0
}

Running result:

Tick at: 1s2ms72us188ns
Tick at: 2s4ms185us160ns
Tick at: 3s6ms275us464ns
Tick at: 4s8ms18us399ns
Tick at: 5s9ms621us394ns

static func repeatDuring(Duration, Duration, Duration, ()->Unit, CatchupStyle)

public static func repeatDuring(period: Duration, delay: Duration, interval: Duration, task: () -> Unit, style!: CatchupStyle = Burst): Timer

Description: Sets and starts a repetitive scheduled task, specifies the maximum duration of the repetition period, and returns the Timer object instance that controls the task.

Parameters:

  • period: maximum duration of the repetition period, for which timing starts after delay; value range: (Duration.Zero, Duration.Max]
  • delay: interval between the current time and the time when the task is executed; value range: [Duration.Min, Duration.Max]. If the value is less than or equal to Duration.Zero, the task is executed immediately.
  • interval: interval between two task executions; value range: (Duration.Zero, Duration.Max]
  • task: task to be executed as scheduled
  • style: catch-up policy; default value: Burst. If the execution duration of a task is too long, the execution times of subsequent tasks may be delayed. Different catch-up policies apply to different scenarios. For details, see CatchupStyle description.

Returns: Timer object instance

Throws:

Example:

import std.sync.{Timer, sleep}
import std.time.{Duration, MonoTime}

main() {
    let start = MonoTime.now()
    Timer.repeatDuring(Duration.second * 5, Duration.second, Duration.second, {=>
        println("Tick at: ${MonoTime.now() - start}")
    })

    sleep(Duration.second * 7)
    0
}

Running result:

Tick at: 1s2ms372us626ns
Tick at: 2s4ms714us879ns
Tick at: 3s6ms769us623ns
Tick at: 4s8ms780us235ns
Tick at: 5s660us104ns
Tick at: 6s3ms257us508ns

static func repeatTimes(Int64, Duration, Duration, ()->Unit, CatchupStyle)

public static func repeatTimes(count: Int64, delay: Duration, interval: Duration, task: () -> Unit, style!: CatchupStyle = Burst): Timer

Description: Sets and starts a repetitive scheduled task, specifies the maximum number of execution times of the task, and returns the Timer object instance that controls the task.

Parameters:

  • count: maximum number of execution times of the task; value range: (0, Int64.Max]
  • delay: interval between the current time and the time when the task is executed; value range: [Duration.Min, Duration.Max]. If the value is less than or equal to Duration.Zero, the task is executed immediately.
  • interval: interval between two task executions; value range: (Duration.Zero, Duration.Max]
  • task: task to be executed as scheduled
  • style: catch-up policy; default value: Burst. If the execution duration of a task is too long, the execution times of subsequent tasks may be delayed. Different catch-up policies apply to different scenarios. For details, see CatchupStyle description.

Returns: Timer object instance

Throws:

Example:

import std.sync.{Timer, sleep}
import std.time.{Duration, MonoTime}

main() {
    let start = MonoTime.now()
    Timer.repeatTimes(3, Duration.second, Duration.second, {=>
        println("Tick at: ${MonoTime.now() - start}")
    })

    sleep(Duration.second * 4)
    0
}

Running result:

Tick at: 1s2ms855us251ns
Tick at: 2s5ms390us18ns
Tick at: 3s7ms935us552ns

func cancel()

public func cancel(): Unit

Description: Cancels a Timer, after which the associated task is no longer scheduled for execution.

An associated task being executed is not interrupted when this function is called. This function does not block the current thread. Calling this function for multiple times is equivalent to calling this function only once.

func hashCode()

public func hashCode(): Int64

Description: Obtains the hash value of a Timer object.

Returns: hash value of the Timer object

operator func !=(Timer)

public operator func !=(rhs: Timer): Bool

Description: Checks whether the current Timer and Timer specified by the input parameter rhs are not the same instance.

Returns:

  • Bool: If the two Timer instances are not the same, true is returned. Otherwise, false is returned.

operator func ==(Timer)

public operator func ==(rhs: Timer): Bool

Description: Checks whether the current Timer and Timer specified by the input parameter rhs are the same instance.

Returns:

  • Bool: If the two Timer instances are the same, true is returned. Otherwise, false is returned.