Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Alternatively, if you want/need to keep the Math::BigInt object intact, you can use threads::shared::shared_clone:

use strict; use threads; use threads::shared; use Math::BigInt; use Data::Dump qw[ pp ]; use feature qw(say); my @numbers = ( 1 .. 10 ); my %result : shared; my @threads = map { threads->create( \&process, $_ ); } @numbers; $_->join for @threads; for my $key ( sort{ $a <=> $b } keys %result ) { say "$key : ", $result{ $key }, ' => ', $result{ $key }->bstr; } sub process { my $number = shift; my $factorial = factorial($number); lock %result; $result{$number} = shared_clone( $factorial ); ## clone the object } sub factorial { my $number = shift; Math::BigInt->bfac($number); }

Produces:

C:\test>junk 1 : Math::BigInt=HASH(0x3f5d160) => 1 2 : Math::BigInt=HASH(0x3f5d190) => 2 3 : Math::BigInt=HASH(0x3f5d148) => 6 4 : Math::BigInt=HASH(0x3f5d178) => 24 5 : Math::BigInt=HASH(0x3f5d118) => 120 6 : Math::BigInt=HASH(0x3f5d130) => 720 7 : Math::BigInt=HASH(0x3f5d160) => 5040 8 : Math::BigInt=HASH(0x3f5d190) => 40320 9 : Math::BigInt=HASH(0x3f5d148) => 362880 10 : Math::BigInt=HASH(0x3f5d178) => 3628800

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

In reply to Re: Threads From Hell #1: How To Share A Hash by BrowserUk
in thread Threads From Hell #1: How To Share A Hash [SOLVED] by karlgoethebier

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-03-29 09:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found