CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
can't lock an object from a base class in a derived class

 



brandonh
New User

Jun 5, 2008, 1:00 PM

Post #1 of 3 (644 views)
can't lock an object from a base class in a derived class Can't Post

Hi,

I'm trying to split a large chunk of code that uses shared variables and I can't get past the error "lock can only be used on shared values". Here's the reduced version of that code, in two files:

***mybase.pm:

package mybase;
use threads;
use threads::shared;

my $mode : shared;
1;

***derived.pm:

#!/usr/bin/perl
package derived;
use strict;
use Exporter;
use threads;
use threads::shared;
use mybase;
use vars qw(@ISA);
@ISA = ('mybase');

sub foo {
lock($mybase::mode);
$mybase::mode = 1;
}

foo();
1;

***
[root@nf-power2 perltest]# ./derived.pm
lock can only be used on shared values at ./derived.pm line 12.

Any ideas on why a variable declared as shared is not appearing as a one?

Thanks,
b


meloyelo
User

Jun 8, 2008, 6:16 PM

Post #2 of 3 (609 views)
Re: [brandonh] can't lock an object from a base class in a derived class [In reply to] Can't Post

Change

my $mode : shared;

to:

our $mode : shared;

in mybase.pm.


brandonh
New User

Jun 10, 2008, 1:19 AM

Post #3 of 3 (597 views)
Re: [meloyelo] can't lock an object from a base class in a derived class [In reply to] Can't Post

Thanks! That did the trick, didn't know about 'our'.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives