
Concurrency and Memory Safe System Software Development with Asynchronous Programming in Rust
"Learn about the principles of concurrency, memory safety, and asynchronous programming in the context of system software development using Rust. Explore topics such as synchronous vs asynchronous functions, spawning asynchronous code, and the performance implications of asynchronous programming. Enhance your understanding of managing asynchronous activities efficiently for parallel execution and optimal resource utilization."
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
E81 CSE 542S: Concurrency and Memory Safe System Software Development Asynchronous Programming Department of Computer Science & Engineering Chris Gill cdgill@wustl.edu 1
Asynchrony I Rust provides synchronous (std::) and asynchronous (async_std::) versions of many useful types and implementations Like net::TcpListener or net::TcpStream Block on calls to synchronous versions E.g., TcpListener::bind(addr); Vs. await asynchronous completion E.g., TcpListener::bind(addr).await; 2 CSE 542S Concurrency and Memory Safe System Software Development
Asynchrony II Asynchronous functions return futures Poll until function completes, returns result A.k.a. the Pi ata programming model Synchronous code can call asynchronous code conveniently in Rust using block_on I.e. block_on does the polling, returns result Can only await on futures from async functions/blocks within asynchronous code Doing so in synchronous code give an error 3 CSE 542S Concurrency and Memory Safe System Software Development
Asynchrony III Asynchronous code can nest and call/await multiple other async functions/blocks at once E.g., async fn run_server can call/await async_std::net::TcpListener::bind then spawn async blocks for accepted connections Each await lets asynchronous code suspend whenever a synch version would block Then, the next poll of its future resumes at the exact place where its execution was suspended Allows multiple asynchronous activities in parallel E.g., sending/receiving on the accepted connections 4 CSE 542S Concurrency and Memory Safe System Software Development
Asynchrony IV Spawning asynchronous code puts futures into a pool of threads that poll to ensure progress awaitcompletion in parallel, get each future s value vs. spawning synchronous threads and performing blocking joins on those threads handles For IO bound activities, spawn_local suffices Runs single core, can use thread-local storage For compute bound activities, use spawn instead Can run multi-core, must use task-local storage Also, all captured values must implement Send trait 5 CSE 542S Concurrency and Memory Safe System Software Development
Asynchrony V Performance of asynchronous code depends strongly on pipelining of data and control flows E.g., parallel execution of code on multiple cores E.g., parallel IO across NIC, filesystem, etc. Needs opportunities for different async blocks & functions to take turns using resources (safely) E.g., design async code so it calls yield_now reasonably frequently (whenever it makes sense) E.g., run code you don t have access to modify within a call to spawn_blocking which runs it in a separate thread and returns a future to await on E.g., Pin types implementing Deref or DerefMut 6 CSE 542S Concurrency and Memory Safe System Software Development
Studio 19 Download async-std crate on Linux Lab machines (will download/build locally, may take a while) Examine Rust s asynchronous programming features like async functions, await expressions, and block_on Practice using those features to develop and run simple server and client programs Studios 12 through 20 are due by 11:59pm on the night before Exam 2 Submit as soon as each is done so you get feedback and can resubmit any that may be marked incomplete 7 CSE 542S Concurrency and Memory Safe System Software Development