use threads; use threads::shared; my ($global):shared; my $handler=threads->create(\&handler)->detach; do { print "Enter a value for shared global variable ( x = exit ): ";ch +omp($global=<>); sleep(3); } while($global ne 'x'); sub handler { my $global_old=$global; while(1) { if($global ne $global_old) { print "User changed the global variable to '$global'.\n"; $global_old=$global; } sleep(1); } }
In reply to Re^9: Execute a sub in the background
by chessgui
in thread Execute a sub in the background
by egzoti4en
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |