Skip to content

Instantly share code, notes, and snippets.

@tadzik
Created September 1, 2012 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tadzik/3580930 to your computer and use it in GitHub Desktop.
Save tadzik/3580930 to your computer and use it in GitHub Desktop.
┌─[tadzik@yavin4]─[~]
└─[%]─> cat threads.nqp
my $a := sub foo() {
nqp::say(5);
nqp::sleep(1);
nqp::say(6);
}
my $b := pir::new__PSP('Task', $a);
my $c := pir::new__PSP('Task', $a);
my $d := pir::new__PSP('Task', $a);
pir::schedule__0P($b);
pir::schedule__0P($c);
pir::schedule__0P($d);
pir::wait__0P($b);
pir::wait__0P($c);
pir::wait__0P($d);
┌─[tadzik@yavin4]─[~]
└─[%]─> time nqp threads.nqp
5
5
5
6
6
6
nqp threads.nqp 0.20s user 0.05s system 19% cpu 1.271 total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment