petdance/scratch — Issue #315: [BUG]  exit of a Coroutine affects all of its sister clones
Author: petdance
Created: 2011-11-01 05:42:01+00:00
State: open
Labels: bug, Pri-normal, Sev-medium

If any clone of a Coroutine dies, then it exits all of the clones. The best way to illustrate is with code:
{{{
$ cat coro.pir
.sub 'main' :main
.const 'Sub' $P99 = 'coro'

.local pmc three, four, five
three = clone $P99
four = clone $P99
five = clone $P99

three(3)
four(4)
five(5)

three()
four()
five()

three()
.end

.sub '' :anon :subid('coro')
.param int x
print x
say '.0'
.yield (x)

print x
say '.1'
.yield (x)

print x
say '.done'
.end
$ ./parrot coro.pir
3.0
4.0
5.0
3.1
4.1
5.1
3.done
4.done
5.done
Cannot resume dead coroutine.
current instr.: 'main' pc 37 (coro.pir:11)
$
}}}

Note that calling the 'three' clone the final time is sufficient to make the 'four' and 'five' clones to also resume + exit (without being explicitly invoked), and leads to the "Cannot resume dead coroutine" exception.

This is very likely to be strongly related to TT #1702.

One possible workaround is to make sure that a coroutine never exits; e.g., by entering an infinite "yield" loop at the end of the Coroutine. This is what PGE has apparently done for quite some time.

Pm

Originally http://trac.parrot.org/parrot/ticket/1710