Deadlock when cancelling coros

Marc Lehmann schmorp at schmorp.de
Fri May 6 19:34:04 CEST 2011


On Fri, May 06, 2011 at 12:58:21PM -0400, Laurent <laurent.aml at gmail.com> wrote:
> The issue is that the DESTROY/guard code trying to use events/condvar
> does not always know whether it will be called from a coro under
> cancellation or from an active coro.

Yes, but it always knows whether it will block or not (or better had to
:).

> So basically, you suggest to not use AnyEvent or coro-aware blocking
> calls (condvar/sleep/unblocked IO/...) within destructors/guards when
> we intend to use coro cancellation.

Yes, basically. You *can* create a new coro to handle the waiting though.

> This is quite a behavior that may deserve a note in the doc, maybe.

I'll think about making it clearer. On the other hand, expecting an
already-cancelled coro to be fully working is stretching it quite a bit,
too.

> Could this kind of deadlock be automatically detected?

Depends - your example deadlocks even if it were allowed (it has an
endless loop in the guard block), and this cannot be detected in general.

Trying to switch and then continuing the cancellation should result in an
assertion failure (or a segfault when assertions are disabled), so while
this is not ideal, context switches during cancellation should be getting
punished already :)

-- 
                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