Artifacts Associated With Ticket cc592ec70d
Ticket change [4ebc6c35fd] (rid 162364) by pooryorick on 2018-04-14 09:28:50:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-fossil-wiki"
- comment initialized to:
The following script, <code><verbatim> coroutine c2 ::apply {{} { yield }} coroutine c1 ::apply [list {} { after 0 { puts [list in coroutine [info coroutine]] yieldto c2 } vwait forever }] </verbatim></code> results in the error, <verbatim> cannot yield: C stack busy </verbatim> - is_private initialized to: "0"
- login: "pooryorick"
- priority initialized to: "5 Medium"
- private_contact initialized to: "e476148cded301ffff84bcdc432536dc0c949e88"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "pooryorick"
- subsystem initialized to: "- New Builtin Commands"
- title initialized to: "vwait not NRE-enabled: C stack busy"
- type initialized to: "Bug"
Ticket change [b0d446b8c9] (rid 162394) by sebres on 2018-04-16 10:02:31:
- icomment:
The problem is here not really the NRE-capability as is. So if vwait get compiled variant it could be interrupted within execute of compiled code. But the question is why it should be - in your example the vwait should wait for variable "forever". But the execution of "yieldto c2" should interrupt the "normal" flow... And in this case either stop the vwait process? Or continue it after exit from c2 (weird for me)? To explain what do you expect, just try to rewrite it with "while", like this: <code><verbatim> set ::forever 1 coroutine c2 ::apply {{} { yield puts [list exit from coroutine [info coroutine]] }} coroutine c1 ::apply [list {} { set c { puts [list in coroutine [info coroutine]] yieldto c2 } while {$::forever} { if {$c ne ""} $c set c "" } puts [list exit from coroutine [info coroutine]] }] </verbatim></code> In above-mentioned example the flow is interrupted and endless wait is interrupted: <code><verbatim> in coroutine ::c1 exit from coroutine ::c2 </verbatim></code> Would it expected in your opinion? <hr/> Just as notice to me: another still worse example (producing segfault ATM): <code><verbatim> coroutine c2 ::apply {{} { yield puts [list interim in coroutine [info coroutine]] yieldto c1 puts [list exit from coroutine [info coroutine]] set ::forever 1 }} coroutine c1 ::apply [list {} { after 0 { puts [list in coroutine [info coroutine]] yieldto c2 } after 1 { puts [list in coroutine [info coroutine]] yieldto c2 } vwait ::forever }] </verbatim></code> - login: "sebres"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [c4a840ca8a] (rid 162395) by sebres on 2018-04-16 12:25:51:
- icomment:
BTW. I assume that "TclNRCoroutineActivateCallback" (resp. inst_yield_to_invoke) are not NRE-safe (and should be fixed regardless of the vwait-repair). Currently any not compiled execution of yield (in body of something not compiled) raises a segfault resp. a panic "tailcall cannot find the right splicing spot: should not happen!" after resume from any "cannot yield: C stack busy"... <code><verbatim> coroutine c2 ::apply {{} { yield puts [list exit from coroutine [info coroutine]] }} coroutine c1 ::apply [list {} { foreach i {0 1} { puts [catch { time { puts [list in coroutine [info coroutine]] yieldto c2 } 1 } res opt]--$res--$opt } }] </verbatim></code> - login: "sebres"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [2febdac6e9] (rid 162411) by sebres on 2018-04-16 18:16:47:
- icomment:
Another problem with yield across vwait/update etc is - event-cycle does not belong to the single interpreter. Theoretically one thread can have multiple interpreters (for example I myself have such systems e. g. with N workers * K interpreters), so despite I don't use coroutines resp. NRE-tailcalls across main-cycle, I would not like to use compiled vwait/update version, because it may cause unexpected (or rather unclear) flow-interruptions within single vwait's across multiple interpreters. Let alone it may not help in such case: I don't know how good such constructs will work within different TEBCResume segments. I'll try to explain: <code><verbatim> I1 -> vwait ... ... DoOneEvent -> any event of I2 I2 -> update ... ... DoOneEvent -> I1-yield is due **BOOM (C stack busy) ** </verbatim></code> So instead of NRE-callback resp. compiled version of vwait/update I can imagine a new interp-state like yieldInProgress, which can freeze execution of the interpreter (yield callback TclNRCoroutineActivateCallback) until the C call stack of it gets the same stackLevel. So it may be something like this: <code><verbatim> TEBCResume: I1 -> vwait ... ... DoOneEvent -> I1-yield is due: if C stack is busy: set I1.yieldInProgress to current callBack and return TCL_YIELD. ... ... if I1.yieldInProgress add callbacks and return to TEBCResume. <- execute yieldInProgress callbacks (we can, because interp == I1 and C-stack is clear) continue vwait-callbacks (e. g. wait further / timeouts, etc.). </verbatim></code> - login: "sebres"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [f072aa19c6] (rid 194921) by pooryorick on 2021-06-20 08:55:43:
- login: "pooryorick"
- mimetype: "text/plain"
- severity changed to: "Severe"
Ticket change [f62e981572] (rid 258485) by serhiy.storchaka on 2026-10-17 08:47:42:
- foundin changed to: "8.6.18, 9.0.5, 9.1.0"
- icomment:
"Cannot yield: C stack busy" from a coroutine in an event handler under <nowiki>[vwait]</nowiki> is the same in all versions: vwait runs the event loop by nested C calls, and making it NRE-aware would be a larger design change. The panic "tailcall cannot find the right splicing spot" after a failed yieldto (sebres' scripts in the comments) was fixed for 9.0 in [eb50e83ee1] ([f9800d52bd]) and is now backported to core-8-6-branch in [d10cadf3ca], tests coroutine-7.13 and coroutine-7.14.
- login: "serhiy.storchaka"
- mimetype: "text/x-fossil-wiki"