Async/Await #1018
Replies: 105 comments 29 replies
-
The thing I was trying to wrap my head around for quite some time, thanks for so detailed explanation! Two minor points:
if !self.waker_cache.contains_key(&task_id) {
self.waker_cache.insert(task_id, self.create_waker(task_id));
}
let waker = self.waker_cache.get(&task_id).expect("should exist"); - why not use the Entry API instead? |
Beta Was this translation helpful? Give feedback.
-
The statemachine in https://os.phil-opp.com/async-await/#the-async-await-pattern fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
loop {
match self { // TODO: handle pinning
ExampleStateMachine::Start(state) => {…}
ExampleStateMachine::WaitingOnFooTxt(state) => {…}
ExampleStateMachine::WaitingOnFooTxt(state) => {…}
ExampleStateMachine::End(state) => {…}
}
}
} Contains the state edit: Fix in #769 |
Beta Was this translation helpful? Give feedback.
-
Excellent! Looking forward to the next article |
Beta Was this translation helpful? Give feedback.
-
@Cerberuser Great to hear that the post is useful to you!
Good question! I tried using it, but it leads to borrowing errors here because we need to borrow
Thanks for reporting! Fixed in f32ee7f. |
Beta Was this translation helpful? Give feedback.
-
@jounathaen Thanks for reporting and providing the fix! |
Beta Was this translation helpful? Give feedback.
-
@senseiod I already started working on it :). |
Beta Was this translation helpful? Give feedback.
-
I'm surprised that on x86 you need to re-enable interrupts before doing a hlt. On cortex m you can do: So the CPU will wake from wfi even with the interrupts disabled. Ofcourse the interrupt handler will only be executed when the interrupts are re-enabled. |
Beta Was this translation helpful? Give feedback.
-
@p2mate Yeah, I think the approach of ARM is definitely better. As far as I know, there is no equivalent to the |
Beta Was this translation helpful? Give feedback.
-
thank you , it's very detailed/clear and very useful. |
Beta Was this translation helpful? Give feedback.
-
Thank you very much for the detailed lesson, and I look forward to continuing. |
Beta Was this translation helpful? Give feedback.
-
There is a repetition typo: "have to have to" in the first paragraph of Thanks for a fascinating article. |
Beta Was this translation helpful? Give feedback.
-
Isn't the uniqueness of TaskId not be guaranteed for zero-sized futures? Box would give the same address for multiple "instances" of the zero sized type. Edit: See this playground link for an example: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=72f510e1edcb7657ce46becab9179977 |
Beta Was this translation helpful? Give feedback.
-
Great article! Thank you so much :) |
Beta Was this translation helpful? Give feedback.
-
Thank you all for the nice feedback :).
Thanks for reporting! Fixed in b6d09c8. |
Beta Was this translation helpful? Give feedback.
-
Very good catch! While zero-sized futures are rare in practice, we should still ensure that they can be used without problems. I opened #782 and #783 to create task IDs using a static counter instead. |
Beta Was this translation helpful? Give feedback.
-
What modifications are needed to divide the virtual memory into kernel space and user space and how context switch can be done. |
Beta Was this translation helpful? Give feedback.
-
We use destructuring to split self into its three fields to avoid some borrow checker errors. Namely, our implementation needs to access the self.task_queue from within a closure, which currently tries to borrow self completely. This is a fundamental borrow checker issue that will be resolved when RFC 2229 is implemented. This RFC was implemented. |
Beta Was this translation helpful? Give feedback.
-
Sad to not see user space and file system here as those were the two I was looking forwards for. |
Beta Was this translation helpful? Give feedback.
-
Please write on |
Beta Was this translation helpful? Give feedback.
-
will there be a new post? |
Beta Was this translation helpful? Give feedback.
-
How do I remove the dots that appear when launching the kernel? |
Beta Was this translation helpful? Give feedback.
-
Just a quick note, the OnceCell struct is now included at core::cell::OnceCell |
Beta Was this translation helpful? Give feedback.
-
Not sure if anyone's still following this post, but turns out after making the changes in this post, To fix this what I did was: // main.rs
#[cfg(test)]
async fn invoke_test_main() {
test_main();
}
pub fn kernel_main(boot_info: &'static BootInfo) -> ! {
// ....
#[cfg(test)] // new
executor.spawn(Task::new(invoke_test_main())); // new
// this will be the returning expression in kernel_main (note the missing semicolon)
executor.run()
} |
Beta Was this translation helpful? Give feedback.
-
Small correction:
No such async
|
Beta Was this translation helpful? Give feedback.
-
Is there anyone can help me understand this sentence? |
Beta Was this translation helpful? Give feedback.
-
are you going to continue the blog? |
Beta Was this translation helpful? Give feedback.
-
Considering we now using async, is it worthy to use |
Beta Was this translation helpful? Give feedback.
-
make it too fast, can't say a good or bad idea |
Beta Was this translation helpful? Give feedback.
-
What about instead of making an executor which executes multiple futures, there was an executor which executed a single future, and then |
Beta Was this translation helpful? Give feedback.
-
This is a general purpose comment thread for the Async/Await post.
Beta Was this translation helpful? Give feedback.
All reactions