?
Solved

Threads - Shared - Reference

Posted on 2004-04-23
3
Medium Priority
?
1,219 Views
Last Modified: 2009-07-29
Hi Friends, I have the following code:

use threads;
use threads::shared;
my $a='abc';
my $b : shared = \$a;

For this, I'm getting the error: Invalid value for shared scalar at del.pl line 4.

Basically, I would like to have a variable(here $b) which is shared and holds a reference. Is this possible? If so please help me.

Thanx
0
Comment
Question by:vi_srikanth
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
Mercantilum earned 1200 total points
ID: 10900848
You can't put a reference to an unshared value in a shared scalar:

use threads;
use threads::shared;
my $bar;
my $foo : shared;
$foo = \$bar;

gives:

Invalid value for shared scalar at x line 5.

See http://www.nntp.perl.org/group/perl.ithreads/758
0
 
LVL 1

Assisted Solution

by:joesp
joesp earned 800 total points
ID: 10902738
why not:

#!/usr/bin/perl
use threads;
use threads::shared;
my $a= "abc";
my $b = &share(\$a);
print $a . "\n";
print $$b . "\n";

0
 
LVL 10

Expert Comment

by:Mercantilum
ID: 10905180
So, you could simply

use threads;
use threads::shared;
my $bar : shared;
my $foo : shared;
$foo = \$bar;
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question