Skip to content

Instantly share code, notes, and snippets.

@FROGGS
Created August 2, 2013 17:38
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 FROGGS/6141772 to your computer and use it in GitHub Desktop.
Save FROGGS/6141772 to your computer and use it in GitHub Desktop.

test script

sub ed_green_thread() { Q:PIR {
    .local pmc interp, task, block, block_name
    .local string name
    interp     = getinterp
    task       = interp.'current_task'()
    block_name = pop task
    name       = block_name
    block      = find_caller_lex name
    block()
} };

sub ed_os_thread() { Q:PIR {
    .param pmc block_name
    .local pmc interp, task, write_task
    interp     = getinterp
    task       = interp.'current_task'()
    block_name = pop task
    write_task = new ['Task']
    push write_task, block_name
    .const 'Sub' $P0 = 'ed_green_thread'
    setattribute write_task, 'code', $P0
    interp.'schedule_proxied'(write_task, block_name)
} };

sub exec_delayed() { Q:PIR {
    .param pmc block_name
    .local pmc task, interp
    task = new ['Task']
    push task, block_name
    .const 'Sub' $P0 = 'ed_os_thread'
    setattribute task, 'code', $P0
    schedule task
} };

my $x := 3;
my $y := 5;
my $z := 11;
my $b := { $z := $x + $y };

exec_delayed('$b');
say(">> $z");
nqp::sleep(1);
say(">> $z");

OUTPUT

>> 11
>> 8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment