If they run on different CPU's, then why do you have to yield() to get other threads to run, on an SMP kernel?
Update... I guess you don't. But in Coro I did have to call cede() in looping threads to let any other thread run.
This works:
use 5.20.0; use threads; sub loop1 { do { print "loop1\n"; sleep 1 } while 1 } sub loop2 { do { print "loop2\n"; sleep 1 } while 1 } my $thr1 = threads->create('loop1'); my $thr2 = threads->create('loop2'); do { print "main\n"; sleep 1 } while 1;
This also works:
use 5.20.0; use threads; my $thr1 = async { do { print "loop1\n"; sleep 1 } while 1 }; my $thr2 = async { do { print "loop2\n"; sleep 1 } while 1 }; do { print "main\n"; sleep 1 } while 1;
This does not work:
use 5.20.0; use Coro; async { do { print "loop1\n"; sleep 1 } while 1 } async { do { print "loop2\n"; sleep 1 } while 1 } do { print "main\n"; sleep 1 } while 1;
In reply to Re^4: Perl Threads and multi-core CPUs
by Mark.Hedges
in thread Perl Threads and multi-core CPUs
by haidut
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |