When the main Coro ends, the program exits and the other Coros are abandonned. Wait for the other Coro at the end of the program if you want it to run to completion.

For example, in this code the first loop will take more time than the second, but after the second one we wait for the first one to complete so the program doesn't exit. If you remove the join call, the program will exit early.

use IO::Handle; use Coro; use Coro::Timer; my $s = async { for (0..11) { Coro::Timer::sleep 0.2; printflush STDOU +T "s"; } }; for (0..9) { Coro::Timer::sleep 0.1; printflush STDOUT "m"; } $s->join;

Also, don't listen to Anon above, for Coro these days doesn't have so much bugs and memory leaks, provided you use a recent version of both Coro and the perl core itself.


In reply to Re: Use Coro for multi-threads, is this right? by ambrus
in thread Use Coro for multi-threads, is this right? by ilxl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.