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

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 {...} ...

Replies are listed 'Best First'.
Re: Re: Re: Re: OO and Threads conflict?
by Anonymous Monk on Sep 20, 2002 at 22:41 UTC
    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". =)