Skip to content

Instantly share code, notes, and snippets.

@ishiduca
Created September 4, 2014 09:41
Show Gist options
  • Save ishiduca/ab2b9b6e0cac627ca474 to your computer and use it in GitHub Desktop.
Save ishiduca/ab2b9b6e0cac627ca474 to your computer and use it in GitHub Desktop.
study coro
use strict;
use warnings;
use Coro;
my $n = 0;
async {
print "async 1 - $n\n";
$n++;
cede;
print "async 2 - $n\n";
$n++;
};
print "main 1 - $n\n";
$n++;
cede;
print "main 2 - $n\n";
$n++;
cede;
print "main 3 - $n\n";
# 出力
# $nはメインプロセスとスレッドで共有している
# main 1 - 0
# async 1 - 1
# main 2 - 2
# async 2 - 3
# main 3 - 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment