Fix API safety for control-flow awaitables like until
when used from tangentially related fibers
#78
Labels
C++ Script API
Good practice
Indicates a proposed change that would be seen as good practice
Memory Safety
module: engine
For features that involve the `engine` module. (optional)
Refactor
Used to flag significant codebase refactors
We currently have a safety issue where calls to
until
and co. from nested lambdas references the outerScript
object, rather than the generatedChildScript
for a sub-thread.i.e. for something like:
we reference the parent thread's
until
member-function, but co_await the result in the sub-thread, making the generated awaitable reference the wrong script object and fiber. This gives unintended behavior as well as hitting a few asserts.The ideal behavior here would be to have things just work™, but if that ends up being too difficult we could always assert early to prevent unwanted side effects.
My working idea to fix this would be to go with the OS thread's currently running
Script
instance, rather than usingself
inuntil
's implementation. This isn't an ideal solution, asself
would not actually have its usual meaning, but it would probably fix the issue.NOTE: It should actually be safe to reference the parent thread from a sub-thread, since the parent should outlive it, but the awaitable's script reference is still an issue here.
The text was updated successfully, but these errors were encountered: