in reply to I lost my "bless"ing.
If you call down and up as functions rather than methods, you can avoid the need to share a reference.
use Thread::Semaphore qw( ); use threads::shared qw( ); BEGIN { *sema_down = \&Thread::Semaphore::down; *sema_up = \&Thread::Semaphore::up; } my $line_semi : shared = 0; ... sema_down(\$line_semi, 1); ... sema_up(\$line_semi, 1);
Update: Alternatively:
use Thread::Semaphore qw( ); use threads::shared qw( is_shared ); BEGIN { package Thread::Semaphore; no warnings 'redefine'; sub new { my $class = shift; if (@_ && is_shared($_[0])) { return bless \$_[0], $class; } else { my $val : shared = @_ ? shift : 1; return bless \$val, $class; } } } my $line_semi_count : shared = 0; my $line_semi = Thread::Semaphore->new($line_semi_count); ... $line_semi->down(1); ... $line_semi->up(1);
Both methods are backwards compatible.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: I lost my "bless"ing.
by Wiggins (Hermit) on Dec 22, 2006 at 15:03 UTC |