Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

by Athanasius (Monsignor)
on Nov 04, 2012 at 14:45 UTC ( #1002203=note: print w/ replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1002203]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (16)
As of 2014-09-22 14:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (195 votes), past polls