The idiom for sharing an object x with POSH is simply x = posh.share(x). This creates a shared object whose initial value is copied from the regular object. The shared object will compare equal to the original object. In other words, x == posh.share(x) will always be true (provided x is shareable).
Besides this form of explicit sharing, objects can also be shared implicitly by assigning them to a shared container object. If a non-shareable object is assigned to a shared container object, an exception is raised.
Since shared types generally inherit their implementations from their shareable counterparts, the result of an operation involving a shared object will generally be a non-shared object. For instance, the result of multiplying two shared integers will be a regular int object. However, since the value is implicitly shared if it is reassigned to a shared container object, this normally behaves as expected. For example,
will behave as expected. The value 'spam spam spam spam ' is computed as a regular string, which is subsequently shared when reassigned to the shared dictionary.
When new processes are created using posh.fork(), objects that are shared will not be duplicated. Rather, they remain accessible to both the parent and child processes. The processes can perform inter-process communication simply by modifying the contents of shared container objects.
All of the standard types for which it makes sense, are shareable. This includes the standard int, long, float, complex, str, unicode, list, tuple and dict types. Figure 3 shows a small example that creates a shared list, forks, and appends one item to the list from both the parent and the child process. The output may vary depending on the way the processes are scheduled, but the consistency of the shared list is always maintained by the implicit synchronization enforced by POSH.