Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Shared variables along threads

Reply
Thread Tools

Shared variables along threads

 
 
Jan Engelhardt
Guest
Posts: n/a
 
      02-09-2004
Hi,


as in threads::shared(3pm) I read that one must use
&share([]);
to make a new array available to all threads. How well does this
work with deeper arrays, i.e. does creating a new array using []
within an already-shared array make that one also shared?



Jan Engelhardt
--
 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      02-09-2004

Jan Engelhardt <(E-Mail Removed)> wrote:
> as in threads::shared(3pm) I read that one must use
> &share([]);


No, one must use
share([]);
or
share [];

Don't use the & unless you know what it does and why you need it to.

> to make a new array available to all threads. How well does this
> work with deeper arrays, i.e. does creating a new array using []
> within an already-shared array make that one also shared?


What happened when you tried it?

Ben

--
For the last month, a large number of PSNs in the Arpa[Inter-]net have been
reporting symptoms of congestion ... These reports have been accompanied by an
increasing number of user complaints ... As of June,... the Arpanet contained
47 nodes and 63 links. [ftp://rtfm.mit.edu/pub/arpaprob.txt] * http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Jan Engelhardt
Guest
Posts: n/a
 
      02-09-2004
>> as in threads::shared(3pm) I read that one must use
>> &share([]);

>
>No, one must use
> share([]);
>or
> share [];


Type of arg 1 to threads::shared::share must be one of [$@%] (not single ref
constructor) at tst.pl line 6, near "];"
Execution of tst.pl aborted due to compilation errors.

6: $mx = share [];

>Don't use the & unless you know what it does and why you need it to.


& executes a user-defined sub, or for that matter, any non-CORE functions such
as print, etc. Since threads is imported as a module, I assume share is a sub,
and not a CORE function. (p. 78 of 'Introduction to Perl', the Llama book)

>> to make a new array available to all threads. How well does this
>> work with deeper arrays, i.e. does creating a new array using []
>> within an already-shared array make that one also shared?

>
>What happened when you tried it?


See above.
>



Jan Engelhardt
--
 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      02-09-2004

Jan Engelhardt <(E-Mail Removed)> wrote:
> >> as in threads::shared(3pm) I read that one must use
> >> &share([]);

> >
> >No, one must use
> > share([]);
> >or
> > share [];

>
> Type of arg 1 to threads::shared::share must be one of [$@%] (not
> single ref constructor) at tst.pl line 6, near "];" Execution of
> tst.pl aborted due to compilation errors.


This is because you can only share a *variable*, not an anonymous
array. The correct solution is not to simply disable the error by
using &: it is there for a reason, and you need to fix your code,
eg. by assigning it to a variable:

my $x = [];
share $x;

> >Don't use the & unless you know what it does and why you need it to.

>
> & executes a user-defined sub, or for that matter, any non-CORE
> functions such as print, etc. Since threads is imported as a module,
> I assume share is a sub, and not a CORE function. (p. 78 of
> 'Introduction to Perl', the Llama book)


Throw that book away and get another. It is *far* too out-of-date to
be any use. Read perldoc perlsub.

Ben

--
For the last month, a large number of PSNs in the Arpa[Inter-]net have been
reporting symptoms of congestion ... These reports have been accompanied by an
increasing number of user complaints ... As of June,... the Arpanet contained
47 nodes and 63 links. [ftp://rtfm.mit.edu/pub/arpaprob.txt] * (E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Put variables into member variables or function variables? tjumail@gmail.com C++ 9 03-23-2008 04:03 PM
Global Shared functions, shared variables Imran Aziz ASP .Net 1 08-22-2005 06:43 PM
Shared Public Variables and Shared Methods Joe Fallon ASP .Net 3 07-16-2004 07:11 AM
Re: Class public shared Variables vs. Application Variables in ASP.NET avnrao ASP .Net 0 05-07-2004 05:28 AM
Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class. DJ Dev ASP .Net 3 02-08-2004 04:19 PM



Advertisments