in reply to Beginner: Threads and Variables
This requires perl5.8.0 compiled with threading, or with a slight modification, perl5+ without threading and using the inspired forks module.use strict; use threads; use threads::shared; print "Started\n"; my $status : shared = 0; my $thr1 = threads->new( sub { sleep(1) and print "thread1: $status\n" while 1; } ); my $thr2 = threads->new( sub { sleep(1) and print "thread2: status incremented\n" while ++$status; } ); $thr1->join; $thr2->join; __output__ Started thread1: 1 thread2: status incremented thread1: 2 thread2: status incremented thread1: 3 thread2: status incremented thread1: 4 ...
_________
broquaint
update: fixed forks link per RMGir's node
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Beginner: Threads and Variables
by RMGir (Prior) on Nov 14, 2002 at 14:20 UTC |