in reply to Re^3: Perl Threads and multi-core CPUs
in thread Perl Threads and multi-core CPUs

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;

Replies are listed 'Best First'.
Re^5: Perl Threads and multi-core CPUs
by BrowserUk (Patriarch) on Jun 27, 2014 at 18:08 UTC
    If they run on different CPU's, then why do you have to yield() to get other threads to run, on an SMP kernel?

    You don't!


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.