Created
May 10, 2016 11:50
-
-
Save lizmat/5b14702303fef6ee68700d23fb4441be to your computer and use it in GitHub Desktop.
proto typing threading on Junctions (worst case any)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use nqp; | |
use MONKEY-TYPING; | |
augment class Junction { | |
method Bool2 { | |
my $states := nqp::getattr($!storage,List,'$!reified'); | |
my int $total = nqp::elems($states); | |
my int $running = 1; | |
my int $jobs = 8; | |
my int $part = ($total div $jobs) + 1; | |
my $promises := nqp::list; | |
my $result; | |
my int $job = -1; | |
my int $start = -$part; | |
nqp::push($promises,Promise.start( | |
-> $start, $elems { | |
my int $i = $start - 1; | |
my int $next = $start + $elems; | |
$next = $total if nqp::isgt_i($next,$total); | |
say "started job #$job in $*THREAD.id() with $i -> $next"; | |
STATEMENT_LIST($result = True; $running = 0) | |
if nqp::atpos($states,$i) | |
while $running && nqp::islt_i(++$i,$next); | |
say "stopping $*THREAD.id() with $i"; | |
}, ($start = $start + $part), $part)) | |
while $running && nqp::islt_i(++$job,$jobs); | |
say "awaiting"; | |
await($promises); | |
nqp::iseq_i($running,1) ?? False !! $result | |
} | |
} | |
say "building junction"; | |
my $a = any(); | |
nqp::bindattr(nqp::getattr(nqp::decont($a),Junction,'$!storage'),List,'$!reified',nqp::setelems(nqp::list,1_000_000)); | |
say "built junction"; | |
say $a.Bool2; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment