ThreadSpecificVariable

public struct ThreadSpecificVariable<T> where T : AnyObject

A ThreadSpecificVariable is a variable that can be read and set like a normal variable except that it holds different variables per thread.

ThreadSpecificVariable is thread-safe so it can be used with multiple threads at the same time but the value returned by currentValue is defined per thread.

Note

ThreadSpecificVariable has reference semantics.
  • Initialize a new ThreadSpecificVariable without a current value (currentValue == nil).

    Declaration

    Swift

    public init()
  • Initialize a new ThreadSpecificVariable with value for the calling thread. After calling this, the calling thread will see currentValue == value but on all other threads currentValue will be nil until changed.

    Declaration

    Swift

    public init(value: T)

    Parameters

    value

    The value to set for the calling thread.

  • The value for the current thread.

    Declaration

    Swift

    public var currentValue: T? { get nonmutating set }