in reply to Beginner: Threads and Variables

Something like this perhaps
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 ...
This requires perl5.8.0 compiled with threading, or with a slight modification, perl5+ without threading and using the inspired forks module.
HTH

_________
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
    the inspired forks module

    Unfortunately, search.cpan.org has issues. Your link takes me to Net::Server::PreForkSimple rather than Elizabeth Mattijsen's forks module.

    You're right, though, that's one cool module.
    --
    Mike