baxy77bax has asked for the wisdom of the Perl Monks concerning the following question:
hi i have an example script in which i'm trying to share a pre-created object.
the problem i can't do that.#!/usr/bin/perl use strict; use threads; use threads::shared; use tmp; my $rf = tmp->new(); share(my @data); my @threads; for ( my $count = 1; $count <= 10; $count++) { my $t = threads->new(\&sub1, $count); push(@threads,$t); } foreach (@threads) { my $num = $_->join; print "done with $num -- @data\n"; } print "End of main program @data\n"; sub sub1 { my $num = shift; print "started thread $num\n"; print "done with thread $num\n"; push (@data,$rf); return $num; } -------------- module tmp.pm package tmp; sub new { my ($class)=@_; my $hash = {}; bless ($hash,$class); } sub _test { my ($self,$arg) = @_; print "testic $arg\n"; } 1;
is there a way to cheat this!thread failed to start: Invalid value for shared scalar at ./test.pl
thnx
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: [threads] Sharing object through threads
by BrowserUk (Patriarch) on Nov 17, 2009 at 10:07 UTC | |
by baxy77bax (Deacon) on Nov 17, 2009 at 12:57 UTC | |
by BrowserUk (Patriarch) on Nov 17, 2009 at 19:27 UTC | |
by ikegami (Patriarch) on Nov 17, 2009 at 19:58 UTC | |
by BrowserUk (Patriarch) on Nov 17, 2009 at 20:46 UTC | |
by ikegami (Patriarch) on Nov 17, 2009 at 22:13 UTC | |
| |
Re: [threads] Sharing object through threads
by Illuminatus (Curate) on Nov 16, 2009 at 21:14 UTC | |
Re: [threads] Sharing object through threads
by zentara (Cardinal) on Nov 17, 2009 at 12:32 UTC | |
Re: [threads] Sharing object through threads
by weismat (Friar) on Nov 17, 2009 at 09:32 UTC |