Cannot understand the nature of data race warnings in Swift 5.10

I agree what you said is correct, because, for example, it's consistent with the output of the example code in this post.

However, do you know where is this behavior documented? I can't find it in SE 304 (structured concurrency). SE 304 says "By default, the task group will schedule child tasks added to the group on the default global concurrent executor". But that's about child tasks not the code in withTaskGroup()'s closure. The slide in this post doesn't help for the same reason.

My hypothesis is that when SE 304 was implemented, the default behavior to run an async func was to run it on the current executor (see the old behavior described in SE 0338). So the behavior of withTaskGroup() wasn't different from other async funcs at that time. That's why SE 304 didn't describe it explicitly. However, after SE 0338 was implemented, the behavior of withTaskGroup() became an exception but isn't documented anywhere. Does anyone know if this understanding is correct? Shouldn't this behavior be documented explicitly?

1 Like