On Wed Aug 10 14:12:37 2022 +0000, Torge Matthies wrote:
So update: I used `HeapValidate` to check if `Context`s stay valid after thread exit if in use. They don't. It only works because either the Context is not used once the chores are running or the data in the memory stays valid enough for it to not crash. So we don't need to do refcounting. This implementation of `_StructuredTaskCollection` here doesn't use the context anyway once the chores are running, so there should rarely (if ever) be crashes if some program doesn't clean up its task collections. For the caching: It seems like there are always n/m Contexts cached, with n = the number of logical CPUs (probably `CurrentScheduler::GetNumberOfVirtualProcessors()`) and more interestingly m = the number of schedulers created (default scheduler + any created with `Scheduler_Create`).
I have tested _StructuredTaskCollection behavior on Context destroy, here are some thoughts: - the _StructuredTaskCollection is not canceled - destructor is not waiting for chores to finish - there's no crash if Context is destroyed while tasks are running/scheduled to run - when context is reused old tasks are gone
I think, that in order to implement it correctly, tasks queue needs to be moved to scheduler. On _Context destroy, all tasks created by the context should be removed from the list.