implication of nesting coroutines

Marc Lehmann schmorp at schmorp.de
Sat Jul 6 07:27:49 CEST 2013


On Sat, Jul 06, 2013 at 01:19:57PM +0800, Michael Fung <mike at 3open.org> wrote:
> 
> [code]
> async {
>   ...
>   db_read();
> }
> 
> sub db_read() {
>   async {
>   ...
>  }
> }
> [/code]
> 
> This is nesting I am afraid?

Ah, so you mean starting a coro inside another coro - that is lexical
nesting of async calls indeed, but the threads themselves are not nested
in any meaningful way: threads have their own life and execution, so
while you can start a thread from within another thread, they don't have
any parent-child relationship, but are indeendent of each other - either
thread can finish before the other, and they can run interleaved as well.

Or in other words, this is completely harmless (and normal programming,
and in fact the whole point of having threads in the first place).

-- 
                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_              http://www.deliantra.net
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      schmorp at schmorp.de
      -=====/_/_//_/\_,_/ /_/\_\



More information about the anyevent mailing list