Thatâs more of a question for the task locals pitch semantics, but letâs quickly address it...
It isnât about the task, it is about the specific fields and their storage.
As I mentioned, reading canceled status is safe since itâs just an atomic load of an atomic status integer in the task. Other more complex operations on the task may not be safe â thatâs it.
Access to task-locals outside of the task is racy semantically (if it is executing, and entering/exiting withLocal blocks, those are mutating the bound values stack â so it is racy what value youâd observe from outside of the task), as well as âweirdâ (why the hell would you do that) so we donât allow for it.
Sure, it can be made thread-safe (by using a treiber stack (simple lock free stack)), but we donât have to since logically we donât want to allow external access anyway, so why would we. It does not make sense to read them outside the task from arbitrary other tasks â so we can avoid synchronization there, making accesses to the locals cheaper. Perhaps weâll do the lockfree stack anyway, but it does not make sense to me to allow âarbitrary random task can read your task localsâ and we should not do this.
For the implementation on how itâs stored, you can refer to the task locals PR which contains a full implementation along with many docs explaining it.