@include <SharedObject>

The SharedObject class provides a base implementation for shared objects that can be used across multiple processes

This is an abstract class and should not be instantiated directly. It provides methods for locking, unlocking, and setting encryption. Subclasses should implement their own methods for reading and writing data.

Internally, it uses the file system to store the shared object state. The file is created with permissions that allow only the owner to read and write.

Methods

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

Parameters

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

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

@SharedObject.unlock

Scope: public

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

This also resets the extended_lock flag to 0.

Usage: @SharedObject.unlock