http://www.perlmonks.org?node_id=1002203


in reply to Re^2: Perl OO: Need a concise way of representing operations on an object
in thread Perl OO: Need a concise way of representing operations on an object

...($foo, $bar, $container) are shared between all Transform objects. This will break thread safety.

No, it won’t.

The variables are shared between Foo::Transform objects within a thread (which doesn’t matter in this case, as they’re explicitly re-initialised in sub transform before being used). But in Perl, whenever a new process or thread is created, the memory is cloned at the point of creation, and thereafter is (by default) not shared (unless this is done explicitly).

For processes, see fork:

File descriptors (and sometimes locks on those descriptors) are shared, while everything else is copied.

For threads, see threads and threads::shared:

By default, variables are private to each thread, and each newly created thread gets a private copy of each existing variable.

Hope that helps,

Athanasius <°(((><contra mundum

  • Comment on Re^3: Perl OO: Need a concise way of representing operations on an object