Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^3: threads::shared variables not really shared... or are they?

by zentara (Archbishop)
on Mar 08, 2008 at 18:47 UTC ( #673009=note: print w/ replies, xml ) Need Help??


in reply to Re^2: threads::shared variables not really shared... or are they?
in thread threads::shared variables not really shared... or are they?

Ooops, you are right, this one gives memory use that agrees with the OP's original script. I think the sleep calls prevent the locking problem. At least on a faster machine. :-)

#!/usr/bin/perl use threads; use threads::shared; my @a : shared; for (1..10) { sleep 1; threads->new(\&foo); } sleep 1; system "grep VmSize /proc/$$/status"; <>; sub foo { for (1..10) { push @a, " " x 1e6; } print @a . " elements in \@a\n"; }

I'm not really a human, but I play one on earth. Cogito ergo sum a bum


Comment on Re^3: threads::shared variables not really shared... or are they?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2015-07-30 00:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls