跳至主要內容

Why Coroutine? (Part 2) — Implementing a Coroutine in C

(the post is automatically translated by AI) Introduction In the previous article, Why Coroutine? (Part 1) — Is Multithreading Not Enough?, we covered the underlying principles of Coroutines and listed the interface we need to implement one in C. In this article, we’ll walk through the code line by line. Source code: GanniPiece/SimpleCCoroutine: A simple coroutine example implemented using C (github.com) Background Knowledge Before we begin, if you’re not familiar with Coroutines, please read the previous article first. In it we mentioned that we can manipulate ucontext_t [1] using four operations defined in <ucontext.h>: ...

October 10, 2022 · 4 min · GanniPiece

Why Coroutine? (Part 1) — Is Multithreading Not Enough?

(the post is automatically translated by AI) Introduction While working with UniVRM [1], I noticed that many Unity development scenarios rely on Coroutines — for example, opening a system file dialog or loading resources. In these situations, Coroutines are chosen to prevent background tasks from disrupting the user experience, such as when loading a large asset causes the window to freeze and the application becomes unresponsive. In this article, I’ll explain what a Coroutine is and compare it with Threads. I’ll then go into more detail about how Coroutines work and wrap up with a brief conclusion. If you’re interested in implementation, see the follow-up article: Why Coroutine? (Part 2) — Implementing a Coroutine in C. ...

May 28, 2022 · 4 min · GanniPiece