Parallel Programming in Rust: A Practical Guide
448 pages
English
PDF
4.5

Parallel Programming in Rust: A Practical Guide

Parallel Programming in Rust: A Practical Guide

Author:

Year:

Summary:

Introduction

The book «Hands-On Concurrency with Rust» (author — Brian Troutwine, 2018, 448 pages) is not just another textbook on the Rust language, but a deep dive into one of the most complex and important topics of modern systems programming: concurrency. Rust is famous for its ability to prevent data races at compile time, but to use this power to its fullest, you need to understand not only the syntax but also the internal mechanics of threads, memory, and synchronization. This is precisely the problem this book solves.

Brian Troutwine is an experienced developer and reliability engineer who has worked with high-load systems. His approach is distinguished by its practicality: each chapter contains not only theory but also ready-made code examples that can be immediately run and modified. The book is aimed at readers already familiar with the basics of Rust and offers a transition from writing simple single-threaded programs to creating complex multithreaded systems.

What is this book about?

The book covers the full spectrum of topics related to concurrency in Rust. It starts with fundamental concepts (threads, mutexes, channels) and gradually moves to advanced techniques: lock-free data structures, atomic operations, memory management (Arc, Cell, RefCell), and asynchronous programming. Special attention is paid to safety — how to avoid deadlocks, livelocks, and other pitfalls.

The book's structure is logical: first you learn to manage threads and synchronize access to data, then you master channels for message passing, and after that you dive into the world of lock-free algorithms and atomic operations. A separate section is dedicated to integration with external libraries (e.g., crossbeam) and writing benchmarks for measuring performance.

Who is this book for?

The book is intended for developers already familiar with Rust (at least at the level of reading and writing simple programs) who want to delve into systems programming and learn to write efficient multithreaded code. It will be useful for:

  • Engineers working on high-load servers and network applications.
  • Developers of game engines and simulations where performance is critical.
  • Specialists in embedded systems and real-time applications.
  • Anyone who wants to understand how Rust ensures the safety of concurrent code at the type level.

What will the reader learn?

After studying the book, you will be able to:

  • Create and manage threads using std::thread, thread pools, and scoped threads.
  • Use synchronization primitives: Mutex, RwLock, Condvar, Barrier.
  • Exchange data via channels (mpsc, crossbeam_channel) and understand the difference between synchronous and asynchronous transmission.
  • Work with atomic operations (AtomicBool, AtomicUsize, etc.) and build lock-free data structures.
  • Apply smart pointers for sharing data between threads: Arc, Rc, Cell, RefCell.
  • Write asynchronous code using async/await (although the book was published before this feature was stabilized, it provides a foundation for understanding).
  • Measure performance and profile concurrent code.
  • Avoid common mistakes: deadlock, livelock, false sharing.

Strengths of the book

The first thing that stands out is the practical focus. Each chapter contains many code examples that can be copied and run. The author is not afraid to show not only correct but also erroneous solutions, explaining why they don't work. This helps to develop the right mindset.

The second is the depth of explanation. Troutwine doesn't just list APIs, but explains how mutexes work under the hood, how the processor handles atomic in

Recommendations