Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2021-06-19
20:50 • Closed ticket [b80ccfcf32]: a coroutine calls yieldto to yieldto itself, and los... artifact: b54adf045b user: pooryorick
20:37 • Ticket [b80ccfcf32]: 3 changes artifact: 5c116979b4 user: dkf
20:23 • Ticket [b80ccfcf32]: 3 changes artifact: 240a17a55f user: dkf
17:05 • Ticket [b80ccfcf32]: 3 changes artifact: 9e116fed4f user: pooryorick
17:01 • Ticket [b80ccfcf32]: 3 changes artifact: bec28492c2 user: pooryorick
16:58 • New ticket [b80ccfcf32]. artifact: d0917825c8 user: pooryorick

a coroutine calls yieldto to yieldto itself, and loses control

Closed / Invalidb80ccfcf323bc45619e14388603176d573a61cf0Created 5 years agoUpdated 5 years ago
Descriptionwiki2021-06-19 16:58:20
As of at least [07f12cf7209a23], core-8-branch, in the following script, control never reaches the [error] command:

proc p0 {} {
	coroutine c2 p1
	error {error after returning from c2}
}


proc p1 {} {
	yieldto yieldto [list [info coroutine]]
}

coroutine c1 p0
puts {no error}

Output:

no error
pooryorick Ticket [b80ccfcf32]: 3 changes [History diff]2021-06-19 17:01:31
pooryorick Ticket [b80ccfcf32]: 3 changes [History diff]2021-06-19 17:05:57
dkfhtml2021-06-19 20:23:55

Do the c1 and c2 coroutines exist afterwards? If they do, can you probe them to see what they're doing?

dkfhtml2021-06-19 20:37:02

c2 doesn't exist; c1 does exist, and is suspended within the call to coroutine

% coroprobe c1 info frame 0
type proc line 2 cmd {coroutine c2 p1} proc ::p0 level 0
Resuming c1 runs the call to error. Neither coroutine exists afterwards.

I'm not sure that this is anything but correct. It's weird, but yielding to a yieldto is weird.

pooryorickwiki2021-06-19 20:50:45

I see now that the example script is doing the right thing. First c2 yields, and the second yieldto then takes place in the context of c1, causing c1 to yield back to c2. c1 is then no longer on the stack, so when p1 returns, it's no longer returning to p0, which is part of thce c1 context. Instead it returns to the caller of c1, as expected.

Log in (anonymous is fine) to add a comment.