I apparently don't understand a scoping or access issue with trying to access my main program's variable from the thread subroutine. I have:
Which prints out:use strict; use Thread; my $time : shared; my $t = Thread->new(\&listener,\$time); while (1) { $time = localtime; print $time,"\n"; sleep 1; } sub listener { my $time_ref = shift; while (1) { { lock($$time_ref); print "\tThread time: [$time]\n"; print "\tThread time: [$main::time]\n"; print "\tThread time: [$$time_ref]\n"; } sleep 3; } }
Indicating to me that the thread only sees the initial value like it has it's own copy. Is that right? How do I access the main threads $time var? Hmmmmm.Wed Feb 9 08:06:02 2005 Thread time: [] Thread time: [] Thread time: [] Wed Feb 9 08:06:03 2005 Wed Feb 9 08:06:04 2005 Wed Feb 9 08:06:05 2005 Thread time: [] Thread time: [] Thread time: [] Wed Feb 9 08:06:06 2005
In reply to Re^2: Thoughts on how to devise a queryable win32 service
by noslenj123
in thread Thoughts on how to devise a queryable win32 service
by noslenj123
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |