hi perl-loop. i'm attempting to use Event, ithreads, and shared variables together.
perl is 5.8.3, Event is 0.87. in particular, i'd like to create a watcher that
watches a shared variable. sample code:
#!/usr/bin/perl
use warnings;
use strict;
use threads;
use threads::shared;
my $data : shared = 0; # the shared variable
#BEGIN {
my $writer = new threads ( sub {
while (1) {
$data++;
print "write: $data (ref is " . \$data . ")\n";
sleep (2);
} } );
#} # end of BEGIN block
use Event;
Event->var (var => \$data,
poll => "w",
cb => sub { print "read: $data (ref is " . \$data . ")\n"; } )
or die "can't register variable watcher";
Event->timer ( interval => 2,
cb => sub { print "timer: $data (ref is " . \$data . ")\n"; } )
or die "can't register timer";
Event::loop ();
... and some output:
[561] [EMAIL PROTECTED] ~ $ ./foo.pl
write: 1 (ref is SCALAR(0x102b0220))
timer: 1 (ref is SCALAR(0x1012bcf8))
write: 2 (ref is SCALAR(0x102b0220))
timer: 2 (ref is SCALAR(0x1012bcf8))
write: 3 (ref is SCALAR(0x102b0220))
timer: 3 (ref is SCALAR(0x1012bcf8))
...
the thing to notice is that the variable watcher never triggers. i guess that might
make sense because the references are different. (that's a guess since i don't really
know how var watchers are implemented.)
how can one create a watcher that watches a shared variable?
tia,
-h
_______________________________________________
No banners. No pop-ups. No kidding.
Make My Way your home on the Web - http://www.myway.com