Class: SharedStack
@include <SharedStack>
The SharedStack class provides a stack implementation that shares its state across multiple instances. This class is useful for scenarios in which we’re forking processes and need a shared stack between them.
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
Echoes the number of elements in the stack.
Usage: @SharedStack.size
@SharedStack.push
Scope: public
Pushes 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.
- Type:
@SharedStack.pop
Scope: public
Pops the top element off the stack and echoes it.
Usage: @SharedStack.pop
@SharedStack.top
Scope: public
Echoes the top element of the stack without removing it.
Usage: @SharedStack.top
@SharedStack.clear
Scope: public
Removes all elements from the stack.
Usage: @SharedStack.clear
@SharedStack.empty
Scope: public
Echoes “true” if the stack is empty, “false” otherwise.
Usage: @SharedStack.empty
@SharedStack.setEncrypted
Scope: public
Sets whether the object should be encrypted. Encrypting the object can mitigate unauthorized reads by other processes.
This cannot be changed after the object has been used.
Usage: @SharedStack.setEncrypted $value
Parameters
value
- Type:
primitive
- ‘1’ or ‘true’ enables encryption, any other value disables it.
- Type:
@SharedStack.lock
Scope: public
Locks 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 access the object while it is locked will block until it is unlocked.
Using this method (as opposed to the internal _lock
method) sets the extended_lock
flag to 1,
indicating that the lock should not be dropped until explicitly unlocked.
I.e., subsequent calls to _unlock
(internal) will not release the lock until unlock
(public) is called.
Usage: @SharedStack.lock
@SharedStack.unlock
Scope: public
Unlocks the shared object, allowing other processes to access it.
This also resets the extended_lock
flag to 0.
Usage: @SharedStack.unlock