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.

C++ Coroutine Theory (2017)

190 pointsby squiguy7over 7 years ago

7 comments

pokoleoover 7 years ago
Waterloo&#x27;s CS 343 (concurrency) course uses coroutines as a stepping block towards understanding concurrent programming.<p>Notes from the course are fantastic, coroutines start here: <a href="https:&#x2F;&#x2F;www.student.cs.uwaterloo.ca&#x2F;~cs343&#x2F;documents&#x2F;notes.pdf#page=33" rel="nofollow">https:&#x2F;&#x2F;www.student.cs.uwaterloo.ca&#x2F;~cs343&#x2F;documents&#x2F;notes.p...</a>
评论 #16320317 未加载
psycover 7 years ago
Do C++ coroutines give you a sane call stack when chained? I’ve only worked with proprietary implementations that do not, and it is an utter catastrophe for maintenance once they have infested a large code base.
评论 #16318535 未加载
评论 #16320901 未加载
评论 #16318533 未加载
评论 #16318746 未加载
评论 #16318485 未加载
KeepFlyingover 7 years ago
Dumb question, but is this something that a dev would expect the compiler to do for us automatically depending on what is deemed most efficient or is this something that a developer can write directly into the code to make it work this way?<p>I want to be sure I understand what is going on here to be sure.<p>Can someone offer an example of where this ability would be particularly useful?
评论 #16319175 未加载
评论 #16318752 未加载
评论 #16326791 未加载
RajuVargheseover 7 years ago
Modula-2, one of the early languages with coroutines, had a pretty simple implementation. With NEWCOROUTINE a new coroutine was created (including the heap memory that would function as a workspace for that coroutine), TRANSFER to transfer control from one coroutine to another and IOTRANSFER to do the same but for interrupts. With these one could design a scheduler and off you went!<p>I had built a coroutine system for a Pascal environment by implementing NEWCOROUTINE and TRANSFER. Both turned out to be pretty simple in assembly language. The workspace contained an area for the CPU registers and the stack. So TRANSFER involved saving the registers of one coroutine in the workspace and restoring the registers from the second.
steveklabnikover 7 years ago
The visualization here is excellent; exactly the kind of thing I&#x27;ve been meaning to look up.
eptcykaover 7 years ago
Seems like this would be more like tokio for Rust rather than Go&#x27;s goroutines.
评论 #16319143 未加载
jnordwickover 7 years ago
Does anybody know if there has been some research and experimentation with inlining? It is probably the most important part of an optimizing compiler, and coroutines would seem to make that very difficult or impossible.
评论 #16323445 未加载