POSH allows different synchronization policies to be applied to different shareable types, according to their synchronization requirements.
Since POSH allows multiple processes to access shared objects concurrently, synchronization may be required to preserve consistency. However, the synchronization requirements may vary from type to type. Immutable objects, such as strings and tuples, are essentially read-only data structures, and may safely be accessed concurrently. Mutable types, such as lists or dictionaries, require access synchronization to ensure that their internal data structures remain in a consistent state. The same goes for all user-defined types that support attribute assignment.
In POSH, the synchronization of access to a shared object is controlled by a special policy object which is associated with its type. When a shareable type is declared using posh.allow_sharing(), the policy object may be specified as an optional argument, and it is later accessible through the special __ synch__ attribute of the shared type. Whenever an operation is performed that requires access to a shared object, a call is made to the shared object's policy object, which may or may not decide to acquire a lock before allowing the operation to be performed. When the operation is complete, a similar call is made to the policy object, and it may release any locks that have been acquired. If the value None is specified for the policy object, unsynchronized access to the shared object is allowed. In addition, POSH defines a policy object that implements monitor access semantics, restricting access to the shared object to one process at a time. Further policy objects may be defined by the user, to provide customized behavior. For instance, a custom policy object could log all method calls that are made to a given shared object, for later reference.