it yields if the task returns Pending when polled. With this poll method, a task can indicate whether they want to yield and give up the CPU, i.e. The most crucial component is the poll method that returns a Poll enum that can be of the two variants Ready(T) and Pending. In Rust, they are represented by the Future trait. In some other languages, like JavaScript, they’re called Promises. Basically, a future is a task that might not be fully finished yet. One way to achieve this is by using futures. If we can allow cooperation, then we can achieve much more efficient context switches and save a bunch more memory. This, however, requires tasks to cooperate and yield to other tasks voluntarily, since we don’t rely on the kernel to police the tasks and force tasks to yield. Imagine if we can context switch only when convenient, such as when we’re waiting for something anyway, and only save exactly what we need to. While this makes it slightly easier to program, at every context switch, the operating system needs to save the value of all CPU registers and the entire call stack of the thread since it has no idea about the progress of the task running in the thread for example, the interrupt could have happened in the middle of a huge recursive computation. This mainly stems from the fact that the kernel can interrupt at any time.
While they definitely have less overhead than full on processes, there’s actually still quite a bit of overhead in this model of concurrency. In a basic operating systems course, we at least learn about OS threads. A short-ish, grossly simplified summary of asynchronous Rust OS Threads So yeah, let me try to write some of this down in a blog post while it’s still fresh in my head. Learning asynchronous Rust, the actor model, and Actix all at once left me scars, scars of knowledge that I will be able to recall forever… until I forget. When I first started working on the automatic updates agent for the Fedora CoreOS operating system, I was in the middle of learning a whole new programming language on top of that, I had to brush up on my asynchronous programming knowledge, get familiar with a new conceptual model of concurrent computation, and learn a whole new Rust framework.
Let me start by thanking the Zincati update agent - you the real MVP. (This article was originally published here on my blog) “OS-scars” awarded by actors