Classes

class AtomicBool

public class AtomicBool {
    public init(val: Bool)
}

Description: Provides functions for atomic operations of the Bool type.

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 by using the default memory ordering mode.

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 current atomic type
  • 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) (deprecated)

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

Description: Performs a CAS operation with the memory ordering mode specified by successOrder used upon success and the memory ordering mode 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.

NOTE

This function will be deprecated in future releases and compareAndSwap(Bool, Bool) will be used instead.

Parameters:

  • old: Bool: value to be compared with the current atomic type
  • new: Bool: value to be written to the atomic type when the two values are equal
  • successOrder!: MemoryOrder (deprecated): memory ordering mode required for the read > modify > write operation when the CAS operation is successful
  • failureOrder!: MemoryOrder (deprecated): memory ordering mode required for the read operation when the CAS operation fails

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 the atomic type by using the default memory ordering mode.

Returns:

  • Bool: value of the current atomic type

func load(MemoryOrder) (deprecated)

public func load(memoryOrder!: MemoryOrder): Bool

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

NOTE

This function will be deprecated in future releases and load() will be used instead.

Parameters:

Returns:

  • Bool: value of the current atomic type

func store(Bool)

public func store(val: Bool): Unit

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

Parameters:

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

func store(Bool, MemoryOrder) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and store(Bool) will be used instead.

Parameters:

  • val: Bool: value to be written to the atomic type
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for the current operation

func swap(Bool)

public func swap(val: Bool): Bool

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

Parameters:

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

Returns:

  • Bool: value before writing

func swap(Bool, MemoryOrder) (deprecated)

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

Description: Performs a swap operation. Specifically, writes the value specified by the val parameter to the atomic type with the memory ordering mode specified by the memoryOrder parameter, and returns the value before writing.

NOTE

This function will be deprecated in future releases and swap(Bool) will be used instead.

Parameters:

  • val: Bool: value to be written to the atomic type
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for the current operation

Returns:

  • Bool: value before writing

class AtomicInt16

public class AtomicInt16 {
    public init(val: Int16)
}

Description: Provides functions for atomic operations of the Int16 type.

init(Int16)

public init(val: Int16)

Description: Constructs an instance of the atomic type AtomicInt16 that encapsulates the Int16 data type. 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 by using the default memory ordering mode.

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 current atomic type
  • 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) (deprecated)

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

Description: Performs a CAS operation with the memory ordering mode specified by successOrder used upon success and the memory ordering mode 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.

NOTE

This function will be deprecated in future releases and compareAndSwap(Int16, Int16) will be used instead.

Parameters:

  • old: Int16: value to be compared with the current atomic type
  • new: Int16: value to be written to the atomic type when the two values are equal
  • successOrder!: MemoryOrder (deprecated): memory ordering mode required for the read > modify > write operation when the CAS operation is successful
  • failureOrder!: MemoryOrder (deprecated): memory ordering mode required for the read operation when the CAS operation fails

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: Performs an addition operation on the value of the atomic type and the val with the default memory ordering mode, writes the result to the atomic type instance, and returns the value before the addition operation.

Parameters:

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

Returns:

  • Int16: value before the addition operation

func fetchAdd(Int16, MemoryOrder) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and fetchAdd(Int16) will be used instead.

Parameters:

Returns:

  • Int16: value before the addition operation

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 value of val with the default memory ordering mode, 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

Returns:

  • Int16: value before the AND operation

func fetchAnd(Int16, MemoryOrder) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and fetchAnd(Int16) will be used instead.

Parameters:

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 value of val with the default memory ordering mode, 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) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and fetchOr(Int16) will be used instead.

Parameters:

  • val: Int16: value to be ORed with the atomic type instance
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for the current operation

Returns:

  • Int16: value before the OR operation

func fetchSub(Int16)

public func fetchSub(val: Int16): Int16

Description: Performs a subtraction operation with the default memory ordering mode. The value of the atomic type is the minuend, and the value of val is the subtrahend. Writes the result to the current atomic type instance and returns the value before the subtraction operation.

Parameters:

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

Returns:

  • Int16: value before the subtraction operation

func fetchSub(Int16, MemoryOrder) (deprecated)

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

Description: Performs a subtraction operation with the memory ordering mode specified by memoryOrder. The value of the atomic type is the minuend, and the value of val is the subtrahend. Writes the result to the current atomic type instance and returns the value before the subtraction operation.

NOTE

This function will be deprecated in future releases and fetchSub(Int16) will be used instead.

Parameters:

  • val: Int16: value to be subtracted from the atomic type instance
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for the current operation

Returns:

  • Int16: value before the subtraction operation

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 value of val with the default memory ordering mode, 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) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and fetchXor(Int16) will be used instead.

Parameters:

  • val: Int16: value to be XORed with the atomic type instance
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for the current operation

Returns:

  • Int16: value before the XOR operation

func load()

public func load(): Int16

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

Returns:

  • Int16: value of the current atomic type

func load(MemoryOrder) (deprecated)

public func load(memoryOrder!: MemoryOrder): Int16

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

NOTE

This function will be deprecated in future releases and load() will be used instead.

Parameters:

Returns:

  • Int16: value of the current atomic type

func store(Int16)

public func store(val: Int16): Unit

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

Parameters:

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

func store(Int16, MemoryOrder) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and store(Int16) will be used instead.

Parameters:

func swap(Int16)

public func swap(val: Int16): Int16

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

Parameters:

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

Returns:

  • Int16: value before writing

func swap(Int16, MemoryOrder) (deprecated)

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

Description: Performs a swap operation. Specifically, writes the value specified by the val parameter to the atomic type with the memory ordering mode specified by the memoryOrder parameter, and returns the value before writing.

NOTE

This function will be deprecated in future releases and swap(Int16) will be used instead.

Parameters:

Returns:

  • Int16: value before writing

class AtomicInt32

public class AtomicInt32 {
    public init(val: Int32)
}

Description: Provides atomic operation functions of the Int32 type.

init(Int32)

public init(val: Int32)

Description: Constructs an instance of the atomic type AtomicInt32 that encapsulates the Int32 data type. 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 by using the default memory ordering mode.

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 current atomic type
  • 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) (deprecated)

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

Description: Performs a CAS operation with the memory ordering mode specified by successOrder used upon success and the memory ordering mode 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.

NOTE

This function will be deprecated in future releases and compareAndSwap(Int32, Int32) will be used instead.

Parameters:

  • old: Int32: value to be compared with the current atomic type
  • new: Int32: value to be written to the atomic type when the two values are equal
  • successOrder!: MemoryOrder (deprecated): memory ordering mode required for the read > modify > write operation when the CAS operation is successful
  • failureOrder!: MemoryOrder (deprecated): memory ordering mode required for the read operation when the CAS operation fails

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: Performs an addition operation on the value of the atomic type and the val with the default memory ordering mode, writes the result to the atomic type instance, and returns the value before the addition operation.

Parameters:

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

Returns:

  • Int32: value before the addition operation

func fetchAdd(Int32, MemoryOrder) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and fetchAdd(Int32) will be used instead.

Parameters:

  • val: Int32: value to be added to the atomic type instance
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for the current operation

Returns:

  • Int32: value before the addition operation

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 value of val with the default memory ordering mode, 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) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and fetchAnd(Int32) will be used instead.

Parameters:

  • val: Int32: value to be ANDed with the atomic type instance
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for 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 value of val with the default memory ordering mode, 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) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and fetchOr(Int32) will be used instead.

Parameters:

  • val: Int32: value to be ORed with the atomic type instance
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for the current operation

Returns:

  • Int32: value before the OR operation

func fetchSub(Int32)

public func fetchSub(val: Int32): Int32

Description: Performs a subtraction operation with the default memory ordering mode. The value of the atomic type is the minuend, and the value of val is the subtrahend. Writes the result to the current atomic type instance and returns the value before the subtraction operation.

Parameters:

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

Returns:

  • Int32: value before the subtraction operation

func fetchSub(Int32, MemoryOrder) (deprecated)

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

Description: Performs a subtraction operation with the memory ordering mode specified by memoryOrder. The value of the atomic type is the minuend and the value of val is the subtrahend. Writes the result to the current atomic type instance and returns the value before the subtraction operation.

NOTE

This function will be deprecated in future releases and fetchSub(Int32) will be used instead.

Parameters:

  • val: Int32: value to be subtracted from the atomic type instance
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for the current operation

Returns:

  • Int32: value before the subtraction operation

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 value of val with the default memory ordering mode, 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) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and fetchXor(Int32) will be used instead.

Parameters:

  • val: Int32: value to be XORed with the atomic type instance
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for the current operation

Returns:

  • Int32: value before the XOR operation

func load()

public func load(): Int32

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

Returns:

  • Int32: value of the current atomic type

func load(MemoryOrder) (deprecated)

public func load(memoryOrder!: MemoryOrder): Int32

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

NOTE

This function will be deprecated in future releases and load() will be used instead.

Parameters:

Returns:

  • Int32: value of the current atomic type

func store(Int32)

public func store(val: Int32): Unit

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

Parameters:

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

func store(Int32, MemoryOrder) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and store(Int32) will be used instead.

Parameters:

func swap(Int32)

public func swap(val: Int32): Int32

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

Parameters:

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

Returns:

  • Int32: value before writing

func swap(Int32, MemoryOrder) (deprecated)

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

Description: Performs a swap operation. Specifically, writes the value specified by the val parameter to the atomic type with the memory ordering mode specified by the memoryOrder parameter, and returns the value before writing.

NOTE

This function will be deprecated in future releases and swap(Int32) will be used instead.

Parameters:

Returns:

  • Int32: value before writing

class AtomicInt64

public class AtomicInt64 {
    public init(val: Int64)
}

Description: Provides atomic operation functions of the Int64 type.

init(Int64)

public init(val: Int64)

Description: Constructs an instance of the atomic type AtomicInt64 that encapsulates the Int64 data type. 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 by using the default memory ordering mode.

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 current atomic type
  • 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) (deprecated)

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

Description: Performs a CAS operation with the memory ordering mode specified by successOrder used upon success and the memory ordering mode 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.

NOTE

This function will be deprecated in future releases and compareAndSwap(Int64, Int64) will be used instead.

Parameters:

  • old: Int64: value to be compared with the current atomic type
  • new: Int64: value to be written to the atomic type when the two values are equal
  • successOrder!: MemoryOrder (deprecated): memory ordering mode required for the read > modify > write operation when the CAS operation is successful
  • failureOrder!: MemoryOrder (deprecated): memory ordering mode required for the read operation when the CAS operation fails

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: Performs an addition operation on the value of the atomic type and the val with the default memory ordering mode, writes the result to the atomic type instance, and returns the value before the addition operation.

Parameters:

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

Returns:

  • Int64: value before the addition operation

func fetchAdd(Int64, MemoryOrder) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and fetchAdd(Int64) will be used instead.

Parameters:

Returns:

  • Int64: value before the addition operation

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 value of val with the default memory ordering mode, 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

Returns:

  • Int64: value before the AND operation

func fetchAnd(Int64, MemoryOrder) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and fetchAnd(Int64) will be used instead.

Parameters:

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 value of val with the default memory ordering mode, 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

Returns:

  • Int64: value before the OR operation

func fetchOr(Int64, MemoryOrder) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and fetchOr(Int64) will be used instead.

Parameters:

Returns:

  • Int64: value before the OR operation

func fetchSub(Int64)

public func fetchSub(val: Int64): Int64

Description: Performs a subtraction operation with the default memory ordering mode. The value of the atomic type is the minuend, and the value of val is the subtrahend. Writes the result to the current atomic type instance and returns the value before the subtraction operation.

Parameters:

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

Returns:

  • Int64: value before the subtraction operation

func fetchSub(Int64, MemoryOrder) (deprecated)

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

Description: Performs a subtraction operation with the memory ordering mode specified by memoryOrder. The value of the atomic type is the minuend and the value of val is the subtrahend. Writes the result to the current atomic type instance and returns the value before the subtraction operation.

NOTE

This function will be deprecated in future releases and fetchSub(Int64) will be used instead.

Parameters:

  • val: Int64: value to be subtracted from the atomic type
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for the current operation

Returns:

  • Int64: value before the subtraction operation

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 value of val with the default memory ordering mode, 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

Returns:

  • Int64: value before the XOR operation

func fetchXor(Int64, MemoryOrder) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and fetchXor(Int64) will be used instead.

Parameters:

Returns:

  • Int64: value before the XOR operation

func load()

public func load(): Int64

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

Returns:

  • Int64: value of the current atomic type

func load(MemoryOrder) (deprecated)

public func load(memoryOrder!: MemoryOrder): Int64

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

NOTE

This function will be deprecated in future releases and load() will be used instead.

Parameters:

Returns:

  • Int64: value of the current atomic type

func store(Int64)

public func store(val: Int64): Unit

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

Parameters:

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

func store(Int64, MemoryOrder) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and store(Int64) will be used instead.

Parameters:

func swap(Int64)

public func swap(val: Int64): Int64

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

Parameters:

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

Returns:

  • Int64: value before writing

func swap(Int64, MemoryOrder) (deprecated)

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

Description: Performs a swap operation. Specifically, writes the value specified by the val parameter to the atomic type with the memory ordering mode specified by the memoryOrder parameter, and returns the value before writing.

NOTE

This function will be deprecated in future releases and swap(Int64) will be used instead.

Parameters:

Returns:

  • Int64: value before writing

Examples:

import std.sync.*

let count = AtomicInt64(1)

main(): Int64 {
    var val1 = 0
    if (count.compareAndSwap(1, 2)) {
        val1 = count.load()
        println("count1 = ${val1}")
    }

    if (count.fetchAdd(2) == val1) {
        var val2 = count.load()
        println("count2 = ${val2}")
    }

    count.store(6)
    var val3 = count.load()
    println("count3 = ${val3}")

    if (count.swap(8) == val3) {
        var val4 = count.load()
        println("count4 = ${val4}")        
    }

    return 0
}

Running result:

count1 = 2
count2 = 4
count3 = 6
count4 = 8

class AtomicInt8

public class AtomicInt8 {
    public init(val: Int8)
}

Description: Provides functions for atomic operations of the Int8 type.

init(Int8)

public init(val: Int8)

Description: Constructs an instance of the atomic type AtomicInt8 that encapsulates the Int8 data type. 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 by using the default memory ordering mode.

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 current atomic type
  • 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) (deprecated)

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

Description: Performs a CAS operation with the memory ordering mode specified by successOrder used upon success and the memory ordering mode 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.

NOTE

This function will be deprecated in future releases and compareAndSwap(Int8, Int8) will be used instead.

Parameters:

  • old: Int8: value to be compared with the current atomic type
  • new: Int8: value to be written to the atomic type when the two values are equal
  • successOrder!: MemoryOrder (deprecated): memory ordering mode required for the read > modify > write operation when the CAS operation is successful
  • failureOrder!: MemoryOrder (deprecated): memory ordering mode required for the read operation when the CAS operation fails

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: Performs an addition operation on the value of the atomic type and the val with the default memory ordering mode, writes the result to the atomic type instance, and returns the value before the addition operation.

Parameters:

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

Returns:

  • Int8: value before the addition operation

func fetchAdd(Int8, MemoryOrder) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and fetchAdd(Int8) will be used instead.

Parameters:

  • val: Int8: value to be added to the atomic type instance
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for the current operation

Returns:

  • Int8: value before the addition operation

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 value of val with the default memory ordering mode, 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) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and fetchAnd(Int8) will be used instead.

Parameters:

  • val: Int8: value to be ANDed with the atomic type instance
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for 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 value of val with the default memory ordering mode, writes the result to the current 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) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and fetchOr(Int8) will be used instead.

Parameters:

  • val: Int8: value to be ORed with the atomic type instance
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for the current operation

Returns:

  • Int8: value before the OR operation

func fetchSub(Int8)

public func fetchSub(val: Int8): Int8

Description: Performs a subtraction operation with the default memory ordering mode. The value of the atomic type is the minuend, and the value of val is the subtrahend. Writes the result to the current atomic type instance and returns the value before the subtraction operation.

Parameters:

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

Returns:

  • Int8: value before the subtraction operation

func fetchSub(Int8, MemoryOrder) (deprecated)

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

Description: Performs a subtraction operation with the memory ordering mode specified by memoryOrder. The value of the atomic type is the minuend and the value of val is the subtrahend. Writes the result to the current atomic type instance and returns the value before the subtraction operation.

NOTE

This function will be deprecated in future releases and fetchSub(Int8) will be used instead.

Parameters:

  • val: Int8: value to be subtracted from the atomic type instance
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for the current operation

Returns:

  • Int8: value before the subtraction operation

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 value of val with the default memory ordering mode, 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) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and fetchXor(Int8) will be used instead.

Parameters:

  • val: Int8: value to be XORed with the atomic type instance
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for the current operation

Returns:

  • Int8: value before the XOR operation

func load()

public func load(): Int8

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

Returns:

  • Int8: value of the atomic type

func load(MemoryOrder) (deprecated)

public func load(memoryOrder!: MemoryOrder): Int8

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

NOTE

This function will be deprecated in future releases and load() will be used instead.

Parameters:

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 the atomic type with the default memory ordering mode.

Parameters:

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

func store(Int8, MemoryOrder) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and store(Int8) will be used instead.

Parameters:

  • val: Int8: value to be written to the atomic type
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for the current operation

func swap(Int8)

public func swap(val: Int8): Int8

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

Parameters:

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

Returns:

  • Int8: value before writing

func swap(Int8, MemoryOrder) (deprecated)

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

Description: Performs a swap operation. Specifically, writes the value specified by the val parameter to the atomic type with the memory ordering mode specified by the memoryOrder parameter, and returns the value before writing.

NOTE

This function will be deprecated in future releases and swap(Int8) will be used instead.

Parameters:

  • val: Int8: value to be written to the atomic type
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for the current operation

Returns:

  • Int8: value before writing

class AtomicOptionReference<T> where T <: Object

public class AtomicOptionReference<T> where T <: Object {
    public init()
    public init(val: Option<T>)
}

Description: Provides functions related to atomic operations of the 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 Option<T> data type. The initial value of the internal data 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 by using the default memory ordering mode.

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 current atomic type
  • 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) (deprecated)

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

Description: Performs a CAS operation with the memory ordering mode specified by successOrder used upon success and the memory ordering mode 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.

NOTE

This function will be deprecated in future releases and compareAndSwap(Option<T>, Option<T>) will be used instead.

Parameters:

  • old: Option<T>: value to be compared with the current atomic type
  • new: Option<T>: value to be written to the atomic type when the two values are equal
  • successOrder!: MemoryOrder (deprecated): memory ordering mode required for the read > modify > write operation when the CAS operation is successful
  • failureOrder!: MemoryOrder (deprecated): memory ordering mode required for the read operation when the CAS operation fails

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 the atomic type by using the default memory ordering mode.

Returns:

  • Option<T>: value of the current atomic type

func load(MemoryOrder) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and load() will be used instead.

Parameters:

Returns:

  • Option<T>: value of the current atomic type

func store(Option<T>)

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

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

Parameters:

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

func store(Option<T>, MemoryOrder) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and store(Option<T>) will be used instead.

Parameters:

func swap(Option<T>)

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

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

Parameters:

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

Returns:

  • Option<T>: value before writing

func swap(Option<T>, MemoryOrder) (deprecated)

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

Description: Performs a swap operation. Specifically, writes the value specified by the val parameter to the atomic type with the memory ordering mode specified by the memoryOrder parameter, and returns the value before writing.

NOTE

This function will be deprecated in future releases and swap(Option<T>) will be used instead.

Parameters:

Returns:

  • Option<T>: value before writing

class AtomicReference<T> where T <: Object

public class AtomicReference<T> where T <: Object {
    public init(val: T)
}

Description: Provides functions related to atomic operations of the 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 T data type. The initial value of the internal data 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 by using the default memory ordering mode.

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 current atomic type
  • 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) (deprecated)

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

Description: Performs a CAS operation with the memory ordering mode specified by successOrder used upon success and the memory ordering mode 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.

NOTE

This function will be deprecated in future releases and compareAndSwap(T, T) will be used instead.

Parameters:

  • old: T: value to be compared with the current atomic type
  • new: T: value to be written to the atomic type when the two values are equal
  • successOrder!: MemoryOrder (deprecated): memory ordering mode required for the read > modify > write operation when the CAS operation is successful
  • failureOrder!: MemoryOrder (deprecated): memory ordering mode required for the read operation when the CAS operation fails

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 the atomic type by using the default memory ordering mode.

Returns:

  • T: value of the current atomic type

func load(MemoryOrder) (deprecated)

public func load(memoryOrder!: MemoryOrder): T

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

NOTE

This function will be deprecated in future releases and load() will be used instead.

Parameters:

Returns:

  • T: value of the current atomic type

func store(T)

public func store(val: T): Unit

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

Parameters:

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

func store(T, MemoryOrder) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and store(T) will be used instead.

Parameters:

  • val: T: value to be written to the atomic type
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for the current operation

func swap(T)

public func swap(val: T): T

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

Parameters:

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

Returns:

  • T: value before writing

func swap(T, MemoryOrder) (deprecated)

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

Description: Performs a swap operation. Specifically, writes the value specified by the val parameter to the atomic type with the memory ordering mode specified by the memoryOrder parameter, and returns the value before writing.

NOTE

This function will be deprecated in future releases and swap(T) will be used instead.

Parameters:

  • val: T: value to be written to the atomic type
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for the current operation

Returns:

  • T: value before writing

class AtomicUInt16

public class AtomicUInt16 {
    public init(val: UInt16)
}

Description: Provides functions for atomic operations of the UInt16 type.

init(UInt16)

public init(val: UInt16)

Description: Constructs an instance of the atomic type AtomicUInt16 that encapsulates the UInt16 data type. 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 by using the default memory ordering mode.

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 current atomic type
  • 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) (deprecated)

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

Description: Performs a CAS operation with the memory ordering mode specified by successOrder used upon success and the memory ordering mode 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.

NOTE

This function will be deprecated in future releases and compareAndSwap(UInt16, UInt16) will be used instead.

Parameters:

  • old: UInt16: value to be compared with the current atomic type
  • new: UInt16: value to be written to the atomic type when the two values are equal
  • successOrder!: MemoryOrder (deprecated): memory ordering mode required for the read > modify > write operation when the CAS operation is successful
  • failureOrder!: MemoryOrder (deprecated): memory ordering mode required for the read operation when the CAS operation fails

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: Performs an addition operation on the value of the atomic type and the val with the default memory ordering mode, writes the result to the atomic type instance, and returns the value before the addition operation.

Parameters:

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

Returns:

  • UInt16: value before the addition operation

func fetchAdd(UInt16, MemoryOrder) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and fetchAdd(UInt16) will be used instead.

Parameters:

Returns:

  • UInt16: value before the addition operation

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 value of val with the default memory ordering mode, 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

Returns:

  • UInt16: value before the AND operation

func fetchAnd(UInt16, MemoryOrder) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and fetchAnd(UInt16) will be used instead.

Parameters:

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 value of val with the default memory ordering mode, 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

Returns:

  • UInt16: value before the OR operation

func fetchOr(UInt16, MemoryOrder) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and fetchOr(UInt16) will be used instead.

Parameters:

Returns:

  • UInt16: value before the OR operation

func fetchSub(UInt16)

public func fetchSub(val: UInt16): UInt16

Description: Performs a subtraction operation with the default memory ordering mode. The value of the atomic type is the minuend, and the value of val is the subtrahend. Writes the result to the current atomic type instance and returns the value before the subtraction operation.

Parameters:

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

Returns:

  • UInt16: value before the subtraction operation

func fetchSub(UInt16, MemoryOrder) (deprecated)

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

Description: Performs a subtraction operation with the memory ordering mode specified by memoryOrder. The value of the atomic type is the minuend and the value of val is the subtrahend. Writes the result to the current atomic type instance and returns the value before the subtraction operation.

NOTE

This function will be deprecated in future releases and fetchSub(UInt16) will be used instead.

Parameters:

  • val: UInt16: value to be subtracted from the atomic type
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for the current operation

Returns:

  • UInt16: value before the subtraction operation

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 value of val with the default memory ordering mode, 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

Returns:

  • UInt16: value before the XOR operation

func fetchXor(UInt16, MemoryOrder) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and fetchXor(UInt16) will be used instead.

Parameters:

Returns:

  • UInt16: value before the XOR operation

func load()

public func load(): UInt16

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

Returns:

  • UInt16: value of the current atomic type

func load(MemoryOrder) (deprecated)

public func load(memoryOrder!: MemoryOrder): UInt16

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

NOTE

This function will be deprecated in future releases and load() will be used instead.

Parameters:

Returns:

  • UInt16: value of the current atomic type

func store(UInt16)

public func store(val: UInt16): Unit

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

Parameters:

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

func store(UInt16, MemoryOrder) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and store(UInt16) will be used instead.

Parameters:

func swap(UInt16)

public func swap(val: UInt16): UInt16

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

Parameters:

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

Returns:

  • UInt16: value before writing

func swap(UInt16, MemoryOrder) (deprecated)

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

Description: Performs a swap operation. Specifically, writes the value specified by the val parameter to the atomic type with the memory ordering mode specified by the memoryOrder parameter, and returns the value before writing.

NOTE

This function will be deprecated in future releases and swap(UInt16) will be used instead.

Parameters:

Returns:

  • UInt16: value before writing

class AtomicUInt32

public class AtomicUInt32 {
    public init(val: UInt32)
}

Description: Provides functions for atomic operations of the UInt32 type.

init(UInt32)

public init(val: UInt32)

Description: Constructs an instance of the atomic type AtomicUInt32 that encapsulates the UInt32 data type. 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 by using the default memory ordering mode.

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 current atomic type
  • 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) (deprecated)

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

Description: Performs a CAS operation with the memory ordering mode specified by successOrder used upon success and the memory ordering mode 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.

NOTE

This function will be deprecated in future releases and compareAndSwap(UInt32, UInt32) will be used instead.

Parameters:

  • old: UInt32: value to be compared with the current atomic type
  • new: UInt32: value to be written to the atomic type when the two values are equal
  • successOrder!: MemoryOrder (deprecated): memory ordering mode required for the read > modify > write operation when the CAS operation is successful
  • failureOrder!: MemoryOrder (deprecated): memory ordering mode required for the read operation when the CAS operation fails

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: Performs an addition operation on the value of the atomic type and the val with the default memory ordering mode, writes the result to the atomic type instance, and returns the value before the addition operation.

Parameters:

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

Returns:

  • UInt32: value before the addition operation

func fetchAdd(UInt32, MemoryOrder) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and fetchAdd(UInt32) will be used instead.

Parameters:

Returns:

  • UInt32: value before the addition operation

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 value of val with the default memory ordering mode, 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) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and fetchAnd(UInt32) will be used instead.

Parameters:

  • val: UInt32: value to be ANDed with the atomic type instance
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for 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 value of val with the default memory ordering mode, 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) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and fetchOr(UInt32) will be used instead.

Parameters:

  • val: UInt32: value to be ORed with the atomic type instance
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for the current operation

Returns:

  • UInt32: value before the OR operation

func fetchSub(UInt32)

public func fetchSub(val: UInt32): UInt32

Description: Performs a subtraction operation with the default memory ordering mode. The value of the atomic type is the minuend, and the value of val is the subtrahend. Writes the result to the current atomic type instance and returns the value before the subtraction operation.

Parameters:

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

Returns:

  • UInt32: value before the subtraction operation

func fetchSub(UInt32, MemoryOrder) (deprecated)

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

Description: Performs a subtraction operation with the memory ordering mode specified by memoryOrder. The value of the atomic type is the minuend and the value of val is the subtrahend. Writes the result to the current atomic type instance and returns the value before the subtraction operation.

NOTE

This function will be deprecated in future releases and fetchSub(UInt32) will be used instead.

Parameters:

  • val: UInt32: value to be subtracted from the atomic type instance
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for the current operation

Returns:

  • UInt32: value before the subtraction operation

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 value of val with the default memory ordering mode, 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) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and fetchXor(UInt32) will be used instead.

Parameters:

  • val: UInt32: value to be XORed with the atomic type instance
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for the current operation

Returns:

  • UInt32: value before the XOR operation

func load()

public func load(): UInt32

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

Returns:

  • UInt32: value of the atomic type

func load(MemoryOrder) (deprecated)

public func load(memoryOrder!: MemoryOrder): UInt32

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

NOTE

This function will be deprecated in future releases and load() will be used instead.

Parameters:

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 the atomic type with the default memory ordering mode.

Parameters:

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

func store(UInt32, MemoryOrder) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and store(UInt32) will be used instead.

Parameters:

func swap(UInt32)

public func swap(val: UInt32): UInt32

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

Parameters:

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

Returns:

  • UInt32: value before writing

func swap(UInt32, MemoryOrder) (deprecated)

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

Description: Performs a swap operation. Specifically, writes the value specified by the val parameter to the atomic type with the memory ordering mode specified by the memoryOrder parameter, and returns the value before writing.

NOTE

This function will be deprecated in future releases and swap(UInt32) will be used instead.

Parameters:

Returns:

  • UInt32: value before writing

class AtomicUInt64

public class AtomicUInt64 {
    public init(val: UInt64)
}

Description: Provides functions for atomic operations of the UInt64 type.

init(UInt64)

public init(val: UInt64)

Description: Constructs an instance of the atomic type AtomicUInt64 that encapsulates the UInt64 data type. 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 by using the default memory ordering mode.

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 current atomic type
  • 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) (deprecated)

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

Description: Performs a CAS operation with the memory ordering mode specified by successOrder used upon success and the memory ordering mode 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.

NOTE

This function will be deprecated in future releases and compareAndSwap(UInt64, UInt64) will be used instead.

Parameters:

  • old: UInt64: value to be compared with the current atomic type
  • new: UInt64: value to be written to the atomic type when the two values are equal
  • successOrder!: MemoryOrder (deprecated): memory ordering mode required for the read > modify > write operation when the CAS operation is successful
  • failureOrder!: MemoryOrder (deprecated): memory ordering mode required for the read operation when the CAS operation fails

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: Performs an addition operation on the value of the atomic type and the val with the default memory ordering mode, writes the result to the atomic type instance, and returns the value before the addition operation.

Parameters:

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

Returns:

  • UInt64: value before the addition operation

func fetchAdd(UInt64, MemoryOrder) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and fetchAdd(UInt64) will be used instead.

Parameters:

  • val: UInt64: value to be added to the atomic type instance
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for the current operation

Returns:

  • UInt64: value before the addition operation

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 value of val with the default memory ordering mode, 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) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and fetchAnd(UInt64) will be used instead.

Parameters:

  • val: UInt64: value to be ANDed with the atomic type instance
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for 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 value of val with the default memory ordering mode, 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

Returns:

  • UInt64: value before the OR operation

func fetchOr(UInt64, MemoryOrder) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and fetchOr(UInt64) will be used instead.

Parameters:

Returns:

  • UInt64: value before the OR operation

func fetchSub(UInt64)

public func fetchSub(val: UInt64): UInt64

Description: Performs a subtraction operation with the default memory ordering mode. The value of the atomic type is the minuend, and the value of val is the subtrahend. Writes the result to the current atomic type instance and returns the value before the subtraction operation.

Parameters:

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

Returns:

  • UInt64: value before the subtraction operation

func fetchSub(UInt64, MemoryOrder) (deprecated)

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

Description: Performs a subtraction operation with the memory ordering mode specified by memoryOrder. The value of the atomic type is the minuend and the value of val is the subtrahend. Writes the result to the current atomic type instance and returns the value before the subtraction operation.

NOTE

This function will be deprecated in future releases and fetchSub(UInt64) will be used instead.

Parameters:

  • val: UInt64: value to be subtracted from the atomic type instance
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for the current operation

Returns:

  • UInt64: value before the subtraction operation

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 value of val with the default memory ordering mode, 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

Returns:

  • UInt64: value before the XOR operation

func fetchXor(UInt64, MemoryOrder) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and fetchXor(UInt64) will be used instead.

Parameters:

Returns:

  • UInt64: value before the XOR operation

func load()

public func load(): UInt64

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

Returns:

  • UInt64: value of the atomic type

func load(MemoryOrder) (deprecated)

public func load(memoryOrder!: MemoryOrder): UInt64

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

NOTE

This function will be deprecated in future releases and load() will be used instead.

Parameters:

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 the atomic type with the default memory ordering mode.

Parameters:

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

func store(UInt64, MemoryOrder) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and store(UInt64) will be used instead.

Parameters:

func swap(UInt64)

public func swap(val: UInt64): UInt64

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

Parameters:

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

Returns:

  • UInt64: value before writing

func swap(UInt64, MemoryOrder) (deprecated)

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

Description: Performs a swap operation. Specifically, writes the value specified by the val parameter to the atomic type with the memory ordering mode specified by the memoryOrder parameter, and returns the value before writing.

NOTE

This function will be deprecated in future releases and swap(UInt64) will be used instead.

Parameters:

Returns:

  • UInt64: value before writing

class AtomicUInt8

public class AtomicUInt8 {
    public init(val: UInt8)
}

Description: Provides functions for atomic operations of the UInt8 type.

init(UInt8)

public init(val: UInt8)

Description: Constructs an instance of the atomic type AtomicUInt8 that encapsulates the UInt8 data type. 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 by using the default memory ordering mode.

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 current atomic type
  • 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) (deprecated)

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

Description: Performs a CAS operation with the memory ordering mode specified by successOrder used upon success and the memory ordering mode 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.

NOTE

This function will be deprecated in future releases and compareAndSwap(UInt8, UInt8) will be used instead.

Parameters:

  • old: UInt8: value to be compared with the current atomic type
  • new: UInt8: value to be written to the atomic type when the two values are equal
  • successOrder!: MemoryOrder (deprecated): memory ordering mode required for the read > modify > write operation when the CAS operation is successful
  • failureOrder!: MemoryOrder (deprecated): memory ordering mode required for the read operation when the CAS operation fails

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: Performs an addition operation on the value of the atomic type and the val with the default memory ordering mode, writes the result to the atomic type instance, and returns the value before the addition operation.

Parameters:

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

Returns:

  • UInt8: value before the addition operation

func fetchAdd(UInt8, MemoryOrder) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and fetchAdd(UInt8) will be used instead.

Parameters:

  • val: UInt8: value to be added to the atomic type instance
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for the current operation

Returns:

  • UInt8: value before the addition operation

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 value of val with the default memory ordering mode, 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) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and fetchAnd(UInt8) will be used instead.

Parameters:

  • val: UInt8: value to be ANDed with the atomic type instance
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for 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 value of val with the default memory ordering mode, 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) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and fetchOr(UInt8) will be used instead.

Parameters:

  • val: UInt8: value to be ORed with the atomic type instance
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for the current operation

Returns:

  • UInt8: value before the OR operation

func fetchSub(UInt8)

public func fetchSub(val: UInt8): UInt8

Description: Performs a subtraction operation with the default memory ordering mode. The value of the atomic type is the minuend, and the value of val is the subtrahend. Writes the result to the current atomic type instance and returns the value before the subtraction operation.

Parameters:

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

Returns:

  • UInt8: value before the subtraction operation

func fetchSub(UInt8, MemoryOrder) (deprecated)

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

Description: Performs a subtraction operation with the memory ordering mode specified by memoryOrder. The value of the atomic type is the minuend and the value of val is the subtrahend. Writes the result to the current atomic type instance and returns the value before the subtraction operation.

NOTE

This function will be deprecated in future releases and fetchSub(UInt8) will be used instead.

Parameters:

  • val: UInt8: value to be subtracted from the atomic type instance
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for the current operation

Returns:

  • UInt8: value before the subtraction operation

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 value of val with the default memory ordering mode, 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) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and fetchXor(UInt8) will be used instead.

Parameters:

  • val: UInt8: value to be XORed with the atomic type instance
  • memoryOrder!: MemoryOrder (deprecated): memory ordering mode used for the current operation

Returns:

  • UInt8: value before the XOR operation

func load()

public func load(): UInt8

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

Returns:

  • UInt8: value of the atomic type

func load(MemoryOrder) (deprecated)

public func load(memoryOrder!: MemoryOrder): UInt8

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

NOTE

This function will be deprecated in future releases and load() will be used instead.

Parameters:

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 the atomic type with the default memory ordering mode.

Parameters:

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

func store(UInt8, MemoryOrder) (deprecated)

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

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

NOTE

This function will be deprecated in future releases and store(UInt8) will be used instead.

Parameters:

func swap(UInt8)

public func swap(val: UInt8): UInt8

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

Parameters:

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

Returns:

  • UInt8: value before writing

func swap(UInt8, MemoryOrder) (deprecated)

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

Description: Performs a swap operation. Specifically, writes the value specified by the val parameter to the atomic type with the memory ordering mode specified by the memoryOrder parameter, and returns the value before writing.

NOTE

This function will be deprecated in future releases and swap(UInt8) will be used instead.

Parameters:

Returns:

  • UInt8: value before writing

class Barrier

public class Barrier {
    public init(count: Int64)
}

Description: Coordinates threads until they run to the same barrier.

Threads reaching the barrier enter the blocked state until all threads reach the barrier 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.

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

Parameters:

  • timeout!: Duration: maximum waiting duration when a thread is blocked. The default value is Duration.Max.

class Monitor (deprecated)

public class Monitor <: ReentrantMutex {
    public init()
}

Description: Blocks a thread to wait for a signal from another thread to resume execution.

This is a mechanism that uses shared variables for thread synchronization. When some suspended threads are waiting for a shared variable condition to be met, other threads change the shared variable so that the condition is met. Then, a wakeup operation is performed. As a result, the execution of the suspended thread can continue after the thread is woken up.

NOTE

This function will be deprecated in future releases and Condition will be used instead.

Parent types:

init()

public init()

Description: Creates a monitor (deprecated) instance using the default constructor.

func notify()

public func notify(): Unit

Description: Wakes up a thread waiting on the monitor.

Throws:

func notifyAll()

public func notifyAll(): Unit

Description: Wakes up all the threads waiting on the monitor.

Throws:

func wait(Duration)

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

Description: Suspends the current thread until the corresponding notify function is called or the suspension time exceeds timeout.

NOTE

When a thread enters the waiting state, the corresponding mutex is released. After being woken up, the thread holds the mutex again.

Parameters:

Returns:

  • Bool: If the monitor (deprecated) is woken up by another thread, true is returned. If timeout occurs, false is returned.

Throws:

class MultiConditionMonitor (deprecated)

public class MultiConditionMonitor <: ReentrantMutex {
    public init()
}

Description: Provides functions for binding multiple condition variables to a mutex.

NOTE

  • This function will be deprecated in future releases and mutex will be used instead.
  • This class is used only when the monitor (deprecated) class is insufficient to implement advanced concurrent algorithms.
  • During initialization, MultiConditionMonitor (deprecated) does not have a related condition variable.
  • Each time newCondition is called, a new waiting queue is created and associated with the current object, and an instance of the conditionID (deprecated) type is returned as the unique identifier.

Parent types:

init()

public init()

Description: Creates a MultiConditionMonitor (deprecated) instance using the default constructor.

func newCondition()

public func newCondition(): ConditionID

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

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 the 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: Suspends the current thread until the corresponding notify function is called.

NOTE

When a thread enters the waiting state, the corresponding mutex is released. After being woken up, the thread holds the mutex again.

Parameters:

Returns:

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

Throws:

class Mutex

public class Mutex <: UniqueLock {
    public init()
}

Description: Provides functionalities related to a reentrant mutex.

The reentrant mutex is used 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 acquire a mutex that has been held by another thread, the thread is blocked and is not woken up until the lock is released. Reentrancy means that a thread can acquire the same lock again.

NOTE

  • Before shared data is accessed, a mutex must be acquired.
  • After the shared data is processed, the mutex must be unlocked for other threads to acquire the mutex.

Parent types:

init()

public init()

Description: Creates a reentrant mutex.

Throws:

func condition()

public func condition(): Condition

Description: Creates a condition related to the mutex object.

It can be used to implement concurrency primitives of "multiple waiting queues for a single lock."

Returns:

Throws:

func lock()

public func lock(): Unit

Description: Acquires a mutex. If a mutex has been held, the other threads are blocked.

func tryLock()

public func tryLock(): Bool

Description: Attempts to acquire a mutex.

Returns:

  • Bool: If a mutex has been held, false is returned; otherwise, the mutex can be held and true is returned.

func unlock

public func unlock(): Unit

Description: Unlocks a mutex.

To completely release a mutex, call this function. Once the mutex is completely released, other blocked threads can be woken up.

Throws:

class ReadWriteLock

public class ReadWriteLock {
    public init(fair!: Bool = false)
}

Description: Provides functionalities related to reentrant read/write locks.

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

Special properties of a read/write lock:

  • Mutual exclusivity of writing: A write lock can be held by only one thread at a time. When a thread holds the write lock, other threads are blocked when attempting to acquire the lock (no matter for read or write) again.
  • Read concurrency: Allows multiple threads to hold a read lock concurrently. When a thread holds the read lock, other threads can still acquire the read lock. Note that other threads are blocked when attempting to acquire the write lock.
  • Reentrance: A thread can acquire a lock repeatedly.
    • A thread holding the write lock can still acquire another write lock or read lock. A lock is completely released only when the lock and unlock operations of the lock are in a one-to-one correspondence.
    • A thread holding the read lock can acquire the read lock again. A lock is completely released only when the lock and unlock operations occur in a one-to-one correspondence. Note that, attempting to hold a write lock when holding a read lock will throw an exception.
  • Lock downgrading: After the process of holding a write lock, holding a read lock, and 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 threads acquiring a read/write lock is not guaranteed.
    • In fair mode, a thread cannot acquire a read lock and enters the waiting state if the read lock has been held by another thread or another thread attempts to acquire a write lock.
    • In fair mode, when a write lock is released, all threads waiting to read are woken up preferentially. When a read lock is released, threads waiting to write are woken up preferentially, while the sequence of wakeup is not guaranteed.

prop readLock

public prop readLock: Lock

Description: Acquires a read lock.

Type: Lock

prop writeLock

public prop writeLock: UniqueLock

Description: Acquires a write lock.

Type: UniqueLock

init(Bool)

public init(fair!: Bool = false)

Description: Constructs a read/write lock.

Parameters:

  • fair!: Bool: Specifies whether the read/write lock is in fair mode. The default value is false, indicating that an unfair read/write lock is constructed.

func isFair()

public func isFair(): Bool

Description: Acquires whether the read/write lock is in fair mode.

Returns:

  • Bool: true indicates the fair mode; false indicates the unfair mode.

class ReentrantMutex (deprecated)

public open class ReentrantMutex <: IReentrantMutex {
    public init()
}

Description: Provides functionalities related to a reentrant mutex.

The reentrant mutex is used 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 acquire a mutex that has been held by another thread, the thread is blocked and is not woken up until the lock is released. Reentrancy means that a thread can acquire the same lock again.

NOTE

  • This function will be deprecated in future releases and mutex will be used instead.
  • ReentrantMutex (deprecated) indicates a built-in mutex. Developers must ensure that it is not inherited.
  • Before shared data is accessed, a mutex must be acquired.
  • After the shared data is processed, the mutex must be unlocked for other threads to acquire the mutex.

Parent types:

init()

public init()

Description: Creates a reentrant mutex.

Throws:

func lock()

public open func lock(): Unit

Description: Acquires a mutex. If a mutex has been held, the other threads are blocked.

func tryLock()

public open func tryLock(): Bool

Description: Attempts to acquire a mutex.

Returns:

  • Bool: If a mutex has been held, false is returned; otherwise, the mutex can be held and true is returned.

func unlock

public open func unlock(): Unit

Description: Unlocks a mutex.

To completely release a mutex, call this function. Once the mutex is completely released, other blocked threads can be woken up.

Throws:

class ReentrantReadMutex (deprecated)

public class ReentrantReadMutex <: ReentrantMutex

Description: Provides the read lock type of the reentrant mutex.

NOTE

This function will be deprecated in the future releases and Lock will be used instead.

Parent types:

func lock()

public func lock(): Unit

Description: Acquires a read lock.

NOTE

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

func tryLock()

public func tryLock(): Bool

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

Returns:

  • Bool: If the read lock is successfully acquired, true is returned. If the read lock is not acquired, 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 the unlock operations is equal to that of the lock operations. If the read lock is released, one of the threads waiting for the write lock is woken up.

Throws:

class ReentrantReadWriteMutex (deprecated)

public class ReentrantReadWriteMutex {
    public init(mode!: ReadWriteMutexMode = ReadWriteMutexMode.Unfair)
}

Description: Provides functionalities related to reentrant read/write locks.

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

NOTE

This function will be deprecated in future releases and ReadWriteLock will be used instead.

Special properties of a read/write lock:

  • Mutual exclusivity of writing: A write lock can be held by only one thread at a time. When a thread holds the write lock, other threads are blocked when attempting to acquire the lock (no matter for read or write) again.
  • Read concurrency: Allows multiple threads to hold a read lock concurrently. When a thread holds the read lock, other threads can still acquire the read lock. Note that other threads are blocked when attempting to acquire the write lock.
  • Reentrance: A thread can acquire a lock repeatedly.
    • A thread holding the write lock can still acquire another write lock or read lock. A lock is completely released only when the lock and unlock operations occur in a one-to-one correspondence.
    • A thread holding the read lock can acquire the read lock again. A lock is completely released only when the lock and unlock operations of the lock are in a one-to-one correspondence. Note that, attempting to hold a write lock when holding a read lock will throw an exception.
  • Lock downgrading: After the process of holding a write lock, holding a read lock, and 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 threads acquiring a read/write lock is not guaranteed.
    • In fair mode, a thread cannot acquire a read lock and enters the waiting state if the read lock has been held by another thread or another thread attempts to acquire a write lock.
    • In fair mode, when a write lock is released, all threads waiting to read are woken up preferentially. When a read lock is released, threads waiting to write are woken up preferentially, while the sequence of wakeup is not guaranteed.

prop readMutex

public prop readMutex: ReentrantReadMutex

Description: Acquires a read lock.

Type: ReentrantReadMutex (deprecated)

prop writeMutex

public prop writeMutex: ReentrantWriteMutex

Description: Acquires a write lock.

Type: ReentrantWriteMutex (deprecated)

init(ReadWriteMutexMode)

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

Description: Constructs a read/write lock.

Parameters:

  • mode!: ReadWriteMutexMode (deprecated): read/write lock mode. The default value is Unfair, indicating that a read/write lock in unfair mode is constructed.

class ReentrantWriteMutex (deprecated)

public class ReentrantWriteMutex <: ReentrantMutex

Description: Provides the write lock type of the reentrant read/write lock.

NOTE

This function will be deprecated in future releases and UniqueLock will be used instead.

Parent types:

func lock()

public func lock(): Unit

Description: Acquires a write lock. Only one thread is allowed to hold the write lock at the same time, and the 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 acquire a write lock. This method does not follow the fair mode when it is used to acquire a read lock.

Returns:

  • Bool: If the write lock is successfully acquired, true is returned. If the write lock is not acquired, 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 the unlock operations is equal to that of the lock operations. If 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 to preferentially wake up the thread waiting for the write lock or the thread waiting for the read lock is determined by specific implementation.

Throws:

class Semaphore

public class Semaphore {
    public init(count: Int64)
}

Description: Provides semaphore-related functionalities.

A semaphore can be considered as a monitor (deprecated) carrying a counter and is often used to control the quantity 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:

  • count: Int64: initial value of the counter. The value range is [0, Int64.Max].

Throws:

func acquire(Int64)

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

Description: Attempts to obtain 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. The default value is 1.

Throws:

  • IllegalArgumentException: If 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 release value accumulated by the internal counter can meet the requirements of the thread that is currently blocked at the semaphore object, 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. The default value is 1.

Returns:

  • Unit: If the value of the current counter is less than the required value, the value fails to be obtained and false is returned. If the value is obtained successfully, true is returned.

Throws:

  • IllegalArgumentException: If 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 cannot be guaranteed.

Parameters:

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

Returns:

  • Bool: If the value of the current counter is less than the required value, the value fails to be obtained and false is returned. If the value is obtained successfully, true is returned.

Throws:

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

class SyncCounter

public class SyncCounter {
    public init(count: Int64)
}

Description: Provides the countdown counter functionalities.

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

prop count

public prop count: Int64

Description: Obtains the current value of a 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 0, all waiting threads are woken up. If the value of the counter is already 0, 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 0 or the waiting duration exceeds timeout.

Parameters:

  • timeout!: Duration: maximum waiting duration when a thread is blocked. The default value is Duration.Max.

class Timer

public class Timer <: Equatable<Timer> & Hashable

Description: Provides the timer functionalities.

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

NOTE

  • The timer class implicitly includes the spawn operation. That is, each timer instance creates a thread to execute its associated task.
  • Each timer instance can be bound to one task only during initialization. After the initialization is completed, 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. The timer class does not guarantee that the task is triggered on time. The timer class ensures that the triggering time of the task is less than or equal to the current time.
  • The timer class does not proactively capture exceptions thrown by the associated task. If any exception to the task is not captured, the timer class becomes invalid.
  • The timer class includes one-off task timers and periodic task timers based on the usage method. When a one-off task timer is used, the task is executed only once. When a periodic 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 when timer is created is met.

Parent types:

static func after(Duration, ()->Option<Duration>)

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

Description: Initializes a timer class. The number of times the associated task is scheduled and executed 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 and executed 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 and executed again immediately.

Parameters:

  • delay: Duration: interval from now to the first time when the associated task is scheduled and executed
  • task: () ->Option<Duration>: task to be scheduled and executed by the 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: Duration: interval from now to the time when the task is executed. The value range is [Duration.Min, Duration.Max]. If the value is less than or equal to Duration.Zero, the task will be executed immediately.
  • task: ()->Unit: task to be executed at the scheduled time

Returns:

  • Timer: generated object instance

Examples:

import std.time.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 periodic scheduled task, and returns the timer object instance that controls the task.

Parameters:

  • delay: Duration: interval from now to the time when the task is executed. The value range is [Duration.Min, Duration.Max]. If the value is less than or equal to Duration.Zero, the task will be executed immediately.
  • interval: Duration: interval between two tasks. The value range is (Duration.Zero, Duration.Max].
  • task: ()->Unit: task to be executed at the scheduled time
  • style!: CatchupStyle: The default catchup policy is the burst policy. If the execution duration of a task is too long, the execution times of subsequent tasks may be delayed. Different catchup policies apply to different scenarios. For details, see CatchupStyle.

Returns:

  • Timer: generated object instance

Throws:

Examples:

import std.sync.{Timer}
import std.time.{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 periodic scheduled task, specifies the maximum duration of the repetition period, and returns the timer object instance that controls the task.

Parameters:

  • Period: Duration: maximum duration of the repetition period, which is counted from the delay. The value range is (Duration.Zero, Duration.Max].
  • delay: Duration: interval from now to the time when the task is executed. The value range is [Duration.Min, Duration.Max]. If the value is less than or equal to Duration.Zero, the task will be executed immediately.
  • interval: Duration: interval between two tasks. The value range is (Duration.Zero, Duration.Max].
  • task: ()->Unit: task to be executed at the scheduled time
  • style!: CatchupStyle: The default catchup policy is the burst policy. If the execution duration of a task is too long, the execution times of subsequent tasks may be delayed. Different catchup policies apply to different scenarios. For details, see CatchupStyle.

Returns:

  • Timer: generated object instance

Throws:

Examples:

import std.sync.{Timer}
import std.time.{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 periodic scheduled task, specifies the maximum duration of the repetition period and returns the timer object instance that controls the task.

Parameters:

  • count: Int64: maximum number of times that the task can be executed. The value range is (0, Int64.Max].
  • delay: Duration: interval from now to the time when the task is executed. The value range is [Duration.Min, Duration.Max]. If the value is less than or equal to Duration.Zero, the task will be executed immediately.
  • interval: Duration: interval between two tasks. The value range is (Duration.Zero, Duration.Max].
  • task: ()->Unit: task to be executed at the scheduled time
  • style!: CatchupStyle: The default catchup policy is the burst policy. If the execution duration of a task is too long, the execution times of subsequent tasks may be delayed. Different catchup policies apply to different scenarios. For details, see CatchupStyle.

Returns:

  • Timer: generated object instance

Throws:

Examples:

import std.sync.{Timer}
import std.time.{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 instance, 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:

  • Int64: hash value of the object

operator func !=(Timer)

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

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

Parameters:

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.

Parameters:

Returns:

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

This function will be deprecated in future releases and load() will be used instead.