Just so you know, those of us who believe in structured concurrency often have slightly different meanings (which I believe will converge over time). My definition is at [0].<p>Beyond libdill, a rough version has now been implemented in C. (By me, sorry for shilling.)<p>An example of it in code is at [1].<p>Combine it with something I call a stackpool (basically a heap-allocated replacement for `alloca()`), and you can worry very little about managing memory manually, even in C.<p>In fact, both together can even serve the same purpose as Rust's borrow checker in C, if you are willing to write your code with a certain style.<p>Once I implement it as a first-class construct in a language (which I'm doing right now), it will look like this:<p><pre><code> threadset
{
// This starts a thread.
go run_thread(arg1, arg2, etc);
// The current thread does not leave
// this block until all threads finish.
}
</code></pre>
I'm happy to answer questions.<p>[0]: <a href="https://gavinhoward.com/2019/12/structured-concurrency-definition/" rel="nofollow">https://gavinhoward.com/2019/12/structured-concurrency-defin...</a><p>[1]: <a href="https://git.yzena.com/Yzena/Yc/src/commit/30f4ae4e471cb5a500da85812619199b4bda5450/src/rig/build.c#L962-L1010" rel="nofollow">https://git.yzena.com/Yzena/Yc/src/commit/30f4ae4e471cb5a500...</a>
Is the basic concept of structured concurrency more about programming language design, or applicable to how a program is structured? I can do something like this in JS:<p><pre><code> async function doTasks(tasks = [])
// Do some concurrent stuff:
let results = await Promises.all(tasks.map((task) => new Promise((resolve, reject) => {
workerpool.exec('mytask', [task])
.then(function(result) {
resolve(result)
})
.catch(function(err) {
reject(err)
})
})))
// Function pauses here until all tasks resolve.
// do stuff with results
}
</code></pre>
The workerpool exists outside the scope of this function, is that kind of the crux of the distinction, or does it come down to how threads / workers are managed (by the language / first class constructs) that outlines the definition of structured concurrency?<p>The example above feels like a similar pattern to what I've seen in discussions of structured concurrency but as with most things I feel like there's an aha moment where I'll get what all the fuss is about.
There's a proposal for a really nice form of structured concurrency in c++ <a href="https://ericniebler.com/2021/08/29/asynchronous-stacks-and-scopes/" rel="nofollow">https://ericniebler.com/2021/08/29/asynchronous-stacks-and-s...</a>
For those interested in exploring Structured Concurrency in JavaScript, there is <a href="https://frontside.com/effection" rel="nofollow">https://frontside.com/effection</a>