Skip to content

Commit

Permalink
Activate t/src/threads_io.t on a threaded Parrot
Browse files Browse the repository at this point in the history
  • Loading branch information
niner committed May 12, 2012
1 parent 9ab1869 commit 627974b
Showing 1 changed file with 58 additions and 10 deletions.
68 changes: 58 additions & 10 deletions t/src/threads_io.t
Expand Up @@ -6,9 +6,12 @@ use strict;
use warnings;
use File::Temp;
use Time::HiRes qw(sleep);
use Parrot::Config;

print "1..0 # SKIP non-blocking or threaded I/O not yet implemented\n";
exit 0;
unless ( $PConfig{HAS_THREADS} ) {
print "1..0 # SKIP non-blocking or threaded I/O not yet implemented\n";
exit 0;
}

# TAP Plan
print "1..4\n";
Expand All @@ -20,27 +23,34 @@ $pir->print(<<'EOF');
#! ./parrot
.sub main :main
.local pmc insub, spinsub, spintask
.local pmc insub, intask, spinsub, spintask, counter
counter = new ['Integer']
counter = 0
set_global 'counter', counter
insub = get_global 'insub'
$P0 = new 'Task', insub
schedule $P0
intask = new 'Task', insub
setattribute intask, 'data', counter
schedule intask
spinsub = get_global 'spin'
spintask = new 'Task', spinsub
setattribute spintask, 'data', counter
schedule spintask
pass
say "ok 2 - main task sleeping"
ok_main('main task sleeping', counter)
sleep 0.5
say "ok 4 - main task back"
ok_main('main task back', counter)
spintask.'kill'()
.end
.sub insub
.local pmc stdin
.param pmc counter
.local pmc stdin, interp
interp = getinterp
stdin = getstdin
$P0 = stdin.'readline'()
Expand All @@ -51,12 +61,13 @@ $pir->print(<<'EOF');
.return()
good:
say "ok 3 - got input"
ok('got input', counter)
.return()
.end
.sub spin
say "ok 1 - spinning"
.param pmc counter
ok('spinning', counter)
$I0 = 0
spin_more:
$I0 = $I0 + 1
Expand All @@ -65,6 +76,43 @@ spin_more:
goto spin_more
.end
.sub ok
.param pmc text
.param pmc counter
.local pmc interp, ok_task, ok_sub
ok_sub = get_global 'ok_core'
ok_task = new ['Task']
setattribute ok_task, 'code', ok_sub
setattribute ok_task, 'data', text
push ok_task, counter
interp = getinterp
interp.'schedule_proxied'(ok_task, counter)
wait ok_task
.end
.sub ok_core
.param pmc text
.local pmc counter, interp, task
interp = getinterp
task = interp.'current_task'()
counter = pop task
inc counter
print 'ok '
print counter
print ' - '
say text
.end
.sub ok_main
.param pmc text
.param pmc counter
inc counter
print 'ok '
print counter
print ' - '
say text
.end
EOF

my $pir_file = $pir->filename;
Expand Down

0 comments on commit 627974b

Please sign in to comment.