Class: SharedVar

@include <SharedVar>

Primitive variable that can be shared between multiple concurrent processes

Reads and writes are atomic and concurrency-safe. The variable can be encrypted for security. Internally, it uses the file system to store the variable state.

Methods

@SharedVar.get

Scope: public

Get the value of the shared variable.

Outputs: The value of the shared variable.

Usage: @SharedVar.get

@SharedVar.set

Scope: public

Set the value of the shared variable.

Usage: @SharedVar.set $value

Parameters

  • value
    • Type: Primitive
    • The value to set for the shared variable.

@SharedVar.setEncrypted

Scope: public

Set whether the object should be encrypted.

Encrypting the object can mitigate unauthorized reads by other processes. This flag cannot be changed after the object has been used.

Returns: 1 if the object has already been used or ‘openssl’ is unavailable, 0 otherwise.

Usage: @SharedVar.setEncrypted $value

Parameters

  • value
    • Type: Primitive
    • ‘1’ or ‘true’ enables encryption, any other value disables it.

@SharedVar.lock

Scope: public

Lock the shared object for exclusive access

Once locked, only the process which locked it can access the object until it is unlocked. Attempts by other processes to access the object will block until it is unlocked.

Returns: 1 if the lock could not be acquired, 0 otherwise.

Usage: @SharedVar.lock

@SharedVar.unlock

Scope: public

Unlock the shared object, allowing other processes to access it.

Returns: 1 if the object was not locked by this process, 0 otherwise.

Usage: @SharedVar.unlock