TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Coroutines in C, revisited

69 点作者 codr4life超过 8 年前

6 条评论

markpapadakis超过 8 年前
This is a C++ coroutines framework( <a href="https:&#x2F;&#x2F;github.com&#x2F;markpapadakis&#x2F;coros-fibers" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;markpapadakis&#x2F;coros-fibers</a> ), but its trivial to “port” it to C.<p>I ‘ve also written a few things about coroutines and fibers(e.g <a href="https:&#x2F;&#x2F;medium.com&#x2F;software-development-2&#x2F;coroutines-and-fibers-why-and-when-5798f08464fd#.qz59082w0" rel="nofollow">https:&#x2F;&#x2F;medium.com&#x2F;software-development-2&#x2F;coroutines-and-fib...</a> and <a href="https:&#x2F;&#x2F;medium.com&#x2F;software-development-2&#x2F;high-performance-services-using-coroutines-ac8e9f54d727#.1s8lfoswb" rel="nofollow">https:&#x2F;&#x2F;medium.com&#x2F;software-development-2&#x2F;high-performance-s...</a> ).<p>Coroutines based on stack manipulation(as opposed to simple FSMs) are extremely powerful and are particularly useful for implementing fair scheduling across runnable ‘processes’ and concurrent execution contexts. Fair scheduling in particular can be really important in the domain of distributed systems that need to process potentially long-running and&#x2F;or expensive request which would otherwise stall processing other cheaper requests indefinitely. Combined with async I&#x2F;O, this gives near optimal concurrency and resources utilisation. Coroutines are often associated (literally and figuratively) with futures&#x2F;promises. See SeaStar framework for a great implementation of those ideas.
评论 #13201215 未加载
btrask超过 8 年前
I just created a submission for libco, which I think is the best (fastest and most portable) library for coroutines in C. It&#x27;s great, I wish it got more love. <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=13199581" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=13199581</a>
评论 #13200762 未加载
clarkmoody超过 8 年前
How does this work compare with libdill[1]?<p>[1] <a href="http:&#x2F;&#x2F;libdill.org&#x2F;" rel="nofollow">http:&#x2F;&#x2F;libdill.org&#x2F;</a>
评论 #13199947 未加载
评论 #13200803 未加载
zserge超过 8 年前
I&#x27;ve recently made a similar protothread&#x2F;coroutine library for embedded systems where local continuations can be either setjmp or goto or case labels. Nothing fancy, but perhaps someone find it useful: <a href="https:&#x2F;&#x2F;github.com&#x2F;zserge&#x2F;pt" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;zserge&#x2F;pt</a>
enqk超过 8 年前
This is a rediscovery of contiki&#x27;s protothreads:<p><a href="http:&#x2F;&#x2F;contiki.sourceforge.net&#x2F;docs&#x2F;2.6&#x2F;a01802.html" rel="nofollow">http:&#x2F;&#x2F;contiki.sourceforge.net&#x2F;docs&#x2F;2.6&#x2F;a01802.html</a>
评论 #13200590 未加载
评论 #13200775 未加载
c-smile超过 8 年前
That appears as a variant of Simon Tatham idea: <a href="http:&#x2F;&#x2F;www.chiark.greenend.org.uk&#x2F;~sgtatham&#x2F;coroutines.html" rel="nofollow">http:&#x2F;&#x2F;www.chiark.greenend.org.uk&#x2F;~sgtatham&#x2F;coroutines.html</a><p>Just in case, I&#x27;ve made C++ variant of it: <a href="https:&#x2F;&#x2F;www.codeproject.com&#x2F;Tips&#x2F;29524&#x2F;Generators-in-C" rel="nofollow">https:&#x2F;&#x2F;www.codeproject.com&#x2F;Tips&#x2F;29524&#x2F;Generators-in-C</a>