in reply to Re: OO and Threads conflict?
in thread OO and Threads conflict?

Nope...

$self->{var} : shared = 1; gives a syntax error. Doesn't matter what you write before it. It's still a syntax error.

Replies are listed 'Best First'.
Re: Re: Re: OO and Threads conflict?
by djantzen (Priest) on Sep 20, 2002 at 22:28 UTC

    What about declaring the variable shared before assigning it to your hash, as in my $var : shared = 1; $self->{var} = \$var. Although on further consideration I wonder if it might be better to be using a package variable via our or use vars since it looks like what you want is a 'static' variable i.e., one shared by all instances of a class, and these constructs provide that behavior. I don't have threads compiled so I can't test this, but this might work:

    package OOThread; use threads; our static_var : shared = 1; # may not be necessary to explicitly shar +e 'our' variables sub new {...} ...

      About that...

      I absolutely, positively and lifethreateningly do NOT want to share a variable between all instances of the class.

      I want to share the variable between two threads, both running in the same object.

      Sharing between threads, not between objects. Vewy vewy impowtant. =) By default threads will get their own copy of all the data (a la fork) except for those vars that are " : shared". =)