Class: SharedStack

@include <SharedStack>

Stack that can be shared between multiple concurrent processes

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

Methods

@SharedStack.size

Scope: public

Echo the number of elements in the stack.

Outputs: The number of elements in the stack.

Usage: @SharedStack.size

@SharedStack.push

Scope: public

Push a value onto the top of the stack.

Usage: @SharedStack.push $value

Parameters

  • value
    • Type: Primitive
    • The value to push onto the top of the stack.

@SharedStack.pop

Scope: public

Pop the top element off the stack and echo it.

Returns: 1 if the stack is empty, 0 otherwise.

Outputs: The value at the top of the stack.

Usage: @SharedStack.pop

@SharedStack.top

Scope: public

Echo the top element of the stack without removing it.

Returns: 1 if the stack is empty, 0 otherwise.

Outputs: The value at the top of the stack.

Usage: @SharedStack.top

@SharedStack.clear

Scope: public

Clear all elements from the stack.

Usage: @SharedStack.clear

@SharedStack.empty

Scope: public

Silently check whether the stack is empty.

Returns: 0 if the stack is empty, 1 otherwise.

Outputs: nothing

Usage: @SharedStack.empty

@SharedStack.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: @SharedStack.setEncrypted $value

Parameters

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

@SharedStack.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: @SharedStack.lock

@SharedStack.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: @SharedStack.unlock