Deadlock when cancelling coros
Laurent
laurent.aml at gmail.com
Fri May 6 00:53:59 CEST 2011
Hi,
I have the following deadlock issue with Coro...
Running this (under Windows):
use common::sense;
use AnyEvent;
use Coro;
use Coro::AnyEvent;
use Guard;
my $coro = async {
my $guard = guard {
while (1) {
print "xxx\n";
# Blocking here
Coro::AnyEvent::sleep(1);
}
};
while (1) {
print "yyy\n";
Coro::AnyEvent::sleep(1);
}
};
Coro::AnyEvent::sleep(1);
print "cancel\n";
$coro->cancel;
print "cancel done\n";
gives that:
yyy
cancel
xxx
and hangs.
The issue seems that as $coro is being cancelled, it is in a kind of
suspended state, so when the guard block gets executed,
Coro::AnyEvent::sleep(1) never returns.
Using $coro->on_destroy(sub {...}) instead of guard works, but this
does not really fit in my real use case, were several objects active
in the cancelled coro expect the coro/AnyEvent->condvar to work when
their DESTROY is called.
Any idea about how to handle this correctly?
Thanks,
-- Laurent
More information about the anyevent
mailing list