|
|
|
|
|
by lpedrosa
1528 days ago
|
|
I don't get the author's conclusion section, especially "structured concurrency does not suffer the colored function problem". Structured concurrency has nothing to do with function colouring. It is how you organise and spawn tasks, so that you can have certain guarantees e.g. the group responds to cancellation as you'd expect, etc. I don't see how async/await plays a part in this. You could have structured concurrency with a os threading model, as opposed to a userland threading model. You can argue that the ergonomics of Zig's async story needs better documentation, especially if you're playing with function pointers. But please don't mislead readers that structured concurrency solves this. |
|
> But please don't mislead readers that structured concurrency solves this.
It absolutely does. The reason is that, in structured concurrency, when a function spawns a thread, you can expect that that thread is joined before the function returns.
For callers, this means that they don't have to worry about whether the function they are calling spawns threads or not; they just call the function, and the function does its thing.
It is the same principle as standard control flow constructs: they use `goto` underneath, but you don't need to worry about the use of `goto` because they guarantee that execution will always end up at the same place afterward (barring early returns and things like that).
So when I say that structured concurrency does not suffer from the colored function problem, what I am saying is that callers, and programmers, do not need to care what functions do underneath when they are called.
Also, structured concurrency solves the function coloring problem because you can use any function, whether it spawns threads or not, as first-class functions, or function pointers, and it all works without needing any special code, or work, or compiler trickery.