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.

Libmill: Go-Style Concurrency in C

233 pointsby Cieplakabout 6 years ago

13 comments

kazinatorabout 6 years ago
The macro should be called <i>select</i>, since that&#x27;s what Go calls it. (Of course I know there is a POSIX function (not C) by that name; so what).<p>This &quot;choose {&quot; &quot;end }&quot; business is an awful way to design the macro. If you need nesting that involves a block, with prolog and epilog material on either or both ends, you just have to hide that into the macro:<p><pre><code> selbegin; out(ch, int, 42): foo(); in(ch, int, i): bar(i); otherwise: baz(); selend; </code></pre> I don&#x27;t understand the downvotes. I have 30 years of (continous!) C experience. This is the best practice for doing a macro like this.<p>This &quot;end }&quot; business has improper nesting, visually. The <i>choose</i> is outside of the braces, the <i>end</i> is within; it is scatter-brained. There is no error checking for a forgotten <i>end</i>.<p>I&#x27;m looking at the implementation and it&#x27;s looking quite weird! <i>choose</i> simply expands into <i>mill_choose_init__</i>, and <i>end</i> expands into <i>mill_choose_end__</i>. The definitions of these seem as if they should pair together:<p><pre><code> #define mill_choose_init__ \ {\ mill_choose_init_(MILL_HERE_);\ int mill_idx = -2;\ while(1) {\ if(mill_idx != -2) {\ if(0) #define mill_choose_end__ \ break;\ }\ }\ mill_idx = mill_choose_wait_();\ } </code></pre> But, oops, look at the obvious lack of balance in the braces.<p><pre><code> mill_choose_init__ { mill_choose_end__ } </code></pre> we are putting a brace after the if (0) which balances the one after break, and the final missing brace that balances the one opened internally in mill_choose_init__.<p>There are best practices to design this sort of macrology that don&#x27;t require the user put braces in weird places to balance the inconsistencies in macro expansions.<p>Speaking as a professional, I would not pass this in a code review.<p>That we have to use a flaky preprocessor in order to get a half decent syntax is already a significant regret. We must not compound the regret by allowing the macrology to be less than as good as it can be.
评论 #19881131 未加载
评论 #19881796 未加载
评论 #19883165 未加载
评论 #19881126 未加载
评论 #19881387 未加载
评论 #19880900 未加载
评论 #19884789 未加载
评论 #19885084 未加载
jwrabout 6 years ago
This is something that would be extremely useful on microcontrollers, where you do lots of event-driven programming. Any sane design ends up with a state machine (or a hierarchy of state machines) driven by events generated in interrupts.<p>Coming from Clojure, I wished for something like core.async on microcontrollers for a long time — a way to convert most of my state machine into sequential code, with the complexity hidden, all while keeping everything in C (converted&#x2F;generated during compile).
评论 #19883435 未加载
评论 #19883879 未加载
评论 #19883500 未加载
评论 #19884871 未加载
评论 #19881181 未加载
AceJohnny2about 6 years ago
There&#x27;s was an episode of the This Week In Tech podcast from 2015 that interviewed LibMill&#x27;s creator about its design concepts:<p><a href="https:&#x2F;&#x2F;twit.tv&#x2F;shows&#x2F;floss-weekly&#x2F;episodes&#x2F;358" rel="nofollow">https:&#x2F;&#x2F;twit.tv&#x2F;shows&#x2F;floss-weekly&#x2F;episodes&#x2F;358</a><p>And HN discussion from 4 years ago: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=10585505" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=10585505</a>
snarfyabout 6 years ago
It seems like development stopped a few years ago. There were steady releases almost monthly for a few years and then it just stops in 2017. Did the author lose interest?<p>Are there any plans to support multicore? I noticed one of the examples addresses this by using fork(). Multicore is something goroutines &gt; 1.5 support.
coliveiraabout 6 years ago
Isn&#x27;t this something already provided by libtask? Libtask was written by Russ Cox.
评论 #19880952 未加载
azhenleyabout 6 years ago
Is libmill safe with garbage collectors (like Boehm GC)?
alexhutchesonabout 6 years ago
How does this compare to boost:Fiber (other than the obvious &quot;it&#x27;s in C, not C++&quot;)?
gigatexalabout 6 years ago
I actually really like the syntax for how they&#x27;re emulating sending and receiving from channels. I like it better than Go&#x27;s way of doing this with the &lt;- operator.<p>What would be nice would be a defer function for closing channels and things.
abbiyaabout 6 years ago
The out and in functions should be swapped to match the go example?
StreamBrightabout 6 years ago
What is Go style in this context? Isn’t it CSP?
yandrypozoabout 6 years ago
who is using libmill by the way? like other open source projects using this library?
jjthebluntabout 6 years ago
Go is Go-style concurrency _almost_ in C.
oneplaneabout 6 years ago
How come neither libmill nor libdill sites have TLS. It&#x27;s almost a chore to set up a site without it nowadays.