Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^2: RFC: Implicit Parallelization Pragma

by Tanktalus (Canon)
on Jan 25, 2005 at 18:09 UTC ( #424971=note: print w/replies, xml ) Need Help??

in reply to Re: RFC: Implicit Parallelization Pragma
in thread RFC: Implicit Parallelization Pragma

All true, but in the spirit of DWIMery, this is actually a benign and irrelevant side effect. The creation of PV from a number is something that will automatically re-happen again later. And thus I think hardburn's code was correct. There are no real side effects in that they cannot be recreated later identically and automatically. For example, if the "use threadsafe" was in code that called a Memoize'd function, there may still be no real side effect. And only the caller can tell that, not perl.

my %cache; sub get_from_cache { my $var = shift; unless (exists $cache{$var}) { $cache{$var} = __PACKAGE__->new($var); } $cache{$var}; } my @foos = do { use threadsafe; map { get_from_cache($_)->foo() } @list; };

Assuming that the object does not have non-local side effects (e.g., it reads from a data store, such as a database or the disk, but does not write to it, and the data store is considered locked from writing, or it merely calculates some stuff), such that removing it from the cache and re-creating it will create precisely the same object (especially the same foo()), then there are no technical side effects, and thus would be threadsafe, even if it's not threadsafe from a pure computer-science perspective.

I have exactly this situation in much of my code at work. I would love to see automatic parallelisation of some of what I do - as it is, I'm forced to fork() on unix, and not use threads at all on Windows, just to get consistant, supported speed boosts where I can. Yes, I lose what modifications child processes create in my objects - but since they are all cached and completely reproducable, there is no real side effect from the child code, except for what it writes to disk.

Of course, in order for this to work, we need a way to signify a subset of the code as serial - for example, when writing to a common logfile. Ok, I'll rephrase this: for it to work, I need that serialisation :-)

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2020-09-29 09:56 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (146 votes). Check out past polls.