13.07.2015 Views

Perl 语言编程 - Linux教程

Perl 语言编程 - Linux教程

Perl 语言编程 - Linux教程

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

my $done = 0;sub frob {my $arg = shift;my $tid = Thread->self->tid;print "thread $tid: frob $arg\n";yield;unless ($done) {yield;$done++;frob($arg + 10);}}如 果 你 这 样 运 行 :my @t;for my $i (1..3) {push @t, Thread->new(\&frob, $i);}for (@t) { $_->join}print "done is $done\n";下 面 是 输 出 ( 哦 , 有 时 候 是 这 样 的 —— 输 出 是 不 可 预 料 的 ):thread 1: frob 1thread 2: frob 2thread 3: frob 3thread 1: frob 11465

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!