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.

Coroutines in C, revisited

69 pointsby codr4lifeover 8 years ago

6 comments

markpapadakisover 8 years ago
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 未加载
btraskover 8 years ago
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 未加载
clarkmoodyover 8 years ago
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 未加载
zsergeover 8 years ago
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>
enqkover 8 years ago
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-smileover 8 years ago
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>