Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
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 scrutinizing the Monastery: (5)
As of 2014-08-22 00:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (144 votes), past polls