My Account Log in

2 options

Asynchronous Programming in Rust : Learn Asynchronous Programming by Building Working Examples of Futures, Green Threads, and Runtimes / Carl Fredrik Samson.

EBSCOhost Academic eBook Collection (North America) Available online

View online

O'Reilly Online Learning: Academic/Public Library Edition Available online

View online
Format:
Book
Author/Creator:
Samson, Carl Fredrik, author.
Language:
English
Subjects (All):
Rust (Computer program language).
Asynchronous transfer mode.
Physical Description:
1 online resource (306 pages)
Edition:
First edition.
Place of Publication:
Birmingham, England : Packt Publishing Ltd., [2024]
Summary:
Get a fundamental understanding of asynchronous programming and Rust's futures by working through examples that show you how everything really works Key Features Master asynchronous Rust through examples focusing on key concepts Build a solid understanding of concepts such as coroutines, fibers, futures, and callbacks Explore Rust's futures, craft your own runtime, and excel in handling stacks, ABIs, syscalls, and inline assembly Purchase of the print or Kindle book includes a free PDF eBook Book Description Step into the world of asynchronous programming with confidence by conquering the challenges of unclear concepts with this hands-on guide. Using functional examples, this book simplifies the trickiest concepts, exploring goroutines, fibers, futures, and callbacks to help you navigate the vast Rust async ecosystem with ease. You'll start by building a solid foundation in asynchronous programming and explore diverse strategies for modeling program flow. The book then guides you through concepts like epoll, coroutines, green threads, and callbacks using practical examples. The final section focuses on Rust, examining futures, generators, and the reactor-executor pattern. You'll apply your knowledge to create your own runtime, solidifying expertise in this dynamic domain. Throughout the book, you'll not only gain proficiency in Rust's async features but also see how Rust models asynchronous program flow. By the end of the book, you'll possess the knowledge and practical skills needed to actively contribute to the Rust async ecosystem. What you will learn Explore the essence of asynchronous program flow and its significance Understand the difference between concurrency and parallelism Gain insights into how computers and operating systems handle concurrent tasks Uncover the mechanics of async/await Understand Rust's futures by implementing them yourself Implement green threads from scratch to thoroughly understand them Who this book is for This book is for programmers who want to enhance their understanding of asynchronous programming, especially those experienced in VM'ed or interpreted languages like C#, Java, Python, JavaScript, and Go. If you work with C or C++ but have had limited exposure to asynchronous programming, this book serves as a resource to broaden your knowledge in this area. Although the examples are predominantly in Rust, the intricacies of Rust's futures are covered in detail. So, anyone with a keen interest in learning Rust or with working knowledge of Rust will be able to get the most out of this book.
Contents:
Cover
Title Page
Copyright
Dedication
Contributors
Table of Contents
Preface
Part 1: Asynchronous Programming Fundamentals
Chapter 1: Concurrency and Asynchronous Programming: a Detailed Overview
Technical requirements
An evolutionary journey of multitasking
Non-preemptive multitasking
Preemptive multitasking
Hyper-threading
Multicore processors
Do you really write synchronous code?
Concurrency versus parallelism
The mental model I use
Let's draw some parallels to process economics
Concurrency and its relation to I/O
What about threads provided by the operating system?
Choosing the right reference frame
Asynchronous versus concurrent
The role of the operating system
Concurrency from the operating system's perspective
Teaming up with the operating system
Communicating with the operating system
The CPU and the operating system
Down the rabbit hole
How does the CPU prevent us from accessing memory we're not supposed to access?
But can't we just change the page table in the CPU?
Interrupts, firmware, and I/O
A simplified overview
Interrupts
Firmware
Summary
Chapter 2: How Programming Languages Model Asynchronous Program Flow
Definitions
Threads
Threads provided by the operating system
Creating new threads takes time
Each thread has its own stack
Context switching
Scheduling
The advantage of decoupling asynchronous operations from OS threads
Example
Fibers and green threads
Each stack has a fixed space
FFI
Callback based approaches
Coroutines: promises and futures
Coroutines and async/await
Chapter 3: Understanding OS-Backed Event Queues, System Calls, and Cross-Platform Abstractions
Running the Linux examples.
Why use an OS-backed event queue?
Blocking I/O
Non-blocking I/O
Event queuing via epoll/kqueue and IOCP
Readiness-based event queues
Completion-based event queues
epoll, kqueue, and IOCP
Cross-platform event queues
System calls, FFI, and cross-platform abstractions
The lowest level of abstraction
The next level of abstraction
The highest level of abstraction
Part 2: Event Queues and Green Threads
Chapter 4: Create Your Own Event Queue
Design and introduction to epoll
Is all I/O blocking?
The ffi module
Bitflags and bitmasks
Level-triggered versus edge-triggered events
The Poll module
The main program
Chapter 5: Creating Our Own Fibers
How to use the repository alongside the book
Background information
Instruction sets, hardware architectures, and ABIs
The System V ABI for x86-64
A quick introduction to Assembly language
An example we can build upon
Setting up our project
An introduction to Rust inline assembly macro
Running our example
The stack
What does the stack look like?
Stack sizes
Implementing our own fibers
Implementing the runtime
Guard, skip, and switch functions
Finishing thoughts
Part 3: Futures and async/await in Rust
Chapter 6: Futures in Rust
What is a future?
Leaf futures
Non-leaf futures
A mental model of an async runtime
What the Rust language and standard library take care of
I/O vs CPU-intensive tasks
Chapter 7: Coroutines and async/await
Introduction to stackless coroutines
An example of hand-written coroutines
Futures module
HTTP module
Do all futures have to be lazy?
Creating coroutines
async/await
coroutine/wait.
corofy-the coroutine preprocessor
b-async-await-an example of a coroutine/wait transformation
c-async-await-concurrent futures
Final thoughts
Chapter 8: Runtimes, Wakers, and the Reactor-Executor Pattern
Introduction to runtimes and why we need them
Reactors and executors
Improving our base example
Design
Changing the current implementation
Creating a proper runtime
Step 1 - Improving our runtime design by adding a Reactor and a Waker
Creating a Waker
Changing the Future definition
Step 2 - Implementing a proper Executor
Step 3 - Implementing a proper Reactor
Experimenting with our new runtime
An example using concurrency
Running multiple futures concurrently and in parallel
Chapter 9: Coroutines, Self-Referential Structs, and Pinning
Improving our example 1 - variables
Setting up the base example
Improving our example 2 - references
Improving our example 3 - this is… not… good…
Discovering self-referential structs
What is a move?
Pinning in Rust
Pinning in theory
Pinning to the heap
Pinning to the stack
Pin projections and structural pinning
Improving our example 4 - pinning to the rescue
future.rs
http.rs
Main.rs
executor.rs
Chapter 10: Creating Your Own Runtime
Setting up our example
main.rs
reactor.rs
Experimenting with our runtime
Challenges with asynchronous Rust
Explicit versus implicit reactor instantiation
Ergonomics versus efficiency and flexibility
Common traits that everyone agrees about
Async drop
The future of asynchronous Rust
Epilogue
Index
About PACKT
Other Books You May Enjoy.
Notes:
Includes index.
Includes bibliographical references and index.
Description based on print version record.
ISBN:
9781805126621
1805126628
OCLC:
1420888105

The Penn Libraries is committed to describing library materials using current, accurate, and responsible language. If you discover outdated or inaccurate language, please fill out this feedback form to report it and suggest alternative language.

My Account

Shelf Request an item Bookmarks Fines and fees Settings

Guides

Using the Library Catalog Using Articles+ Library Account