TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Structured Concurrency

71 pointsby pcr910303about 3 years ago

7 comments

ghowardabout 3 years ago
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&#x27;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&#x27;m doing right now), it will look like this:<p><pre><code> threadset { &#x2F;&#x2F; This starts a thread. go run_thread(arg1, arg2, etc); &#x2F;&#x2F; The current thread does not leave &#x2F;&#x2F; this block until all threads finish. } </code></pre> I&#x27;m happy to answer questions.<p>[0]: <a href="https:&#x2F;&#x2F;gavinhoward.com&#x2F;2019&#x2F;12&#x2F;structured-concurrency-definition&#x2F;" rel="nofollow">https:&#x2F;&#x2F;gavinhoward.com&#x2F;2019&#x2F;12&#x2F;structured-concurrency-defin...</a><p>[1]: <a href="https:&#x2F;&#x2F;git.yzena.com&#x2F;Yzena&#x2F;Yc&#x2F;src&#x2F;commit&#x2F;30f4ae4e471cb5a500da85812619199b4bda5450&#x2F;src&#x2F;rig&#x2F;build.c#L962-L1010" rel="nofollow">https:&#x2F;&#x2F;git.yzena.com&#x2F;Yzena&#x2F;Yc&#x2F;src&#x2F;commit&#x2F;30f4ae4e471cb5a500...</a>
评论 #30738563 未加载
评论 #30738805 未加载
评论 #30739546 未加载
评论 #30747393 未加载
parksyabout 3 years ago
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 = []) &#x2F;&#x2F; Do some concurrent stuff: let results = await Promises.all(tasks.map((task) =&gt; new Promise((resolve, reject) =&gt; { workerpool.exec(&#x27;mytask&#x27;, [task]) .then(function(result) { resolve(result) }) .catch(function(err) { reject(err) }) }))) &#x2F;&#x2F; Function pauses here until all tasks resolve. &#x2F;&#x2F; 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 &#x2F; workers are managed (by the language &#x2F; first class constructs) that outlines the definition of structured concurrency?<p>The example above feels like a similar pattern to what I&#x27;ve seen in discussions of structured concurrency but as with most things I feel like there&#x27;s an aha moment where I&#x27;ll get what all the fuss is about.
评论 #30751892 未加载
评论 #30749848 未加载
评论 #30755851 未加载
pizzaabout 3 years ago
There&#x27;s a proposal for a really nice form of structured concurrency in c++ <a href="https:&#x2F;&#x2F;ericniebler.com&#x2F;2021&#x2F;08&#x2F;29&#x2F;asynchronous-stacks-and-scopes&#x2F;" rel="nofollow">https:&#x2F;&#x2F;ericniebler.com&#x2F;2021&#x2F;08&#x2F;29&#x2F;asynchronous-stacks-and-s...</a>
muxatorabout 3 years ago
I just wanted to mention that this is taken from the blog of Martin Sústrik, one of the original authors of ZeroMQ.
评论 #30740102 未加载
cowboydabout 3 years ago
For those interested in exploring Structured Concurrency in JavaScript, there is <a href="https:&#x2F;&#x2F;frontside.com&#x2F;effection" rel="nofollow">https:&#x2F;&#x2F;frontside.com&#x2F;effection</a>
_ZeD_about 3 years ago
Obligatory trio link <a href="https:&#x2F;&#x2F;trio.readthedocs.io&#x2F;en&#x2F;stable&#x2F;" rel="nofollow">https:&#x2F;&#x2F;trio.readthedocs.io&#x2F;en&#x2F;stable&#x2F;</a>
评论 #30741631 未加载
spepsabout 3 years ago
(2016)
评论 #30738562 未加载