logo资料库

Hands-On Concurrency with Rust.pdf

第1页 / 共678页
第2页 / 共678页
第3页 / 共678页
第4页 / 共678页
第5页 / 共678页
第6页 / 共678页
第7页 / 共678页
第8页 / 共678页
资料共678页,剩余部分请下载后查看
Title Page
Copyright and Credits
Hands-On Concurrency with Rust
Dedication
Packt Upsell
Why subscribe?
PacktPub.com
Contributors
About the author
About the reviewer
Packt is searching for authors like you
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Conventions used
Get in touch
Reviews
Preliminaries – Machine Architecture and Getting Started with Rust
Technical requirements
The machine
The CPU
Memory and caches
Memory model
Getting set up
The interesting part
Debugging Rust programs
Summary
Further reading
Sequential Rust Performance and Testing
Technical requirements
Diminishing returns
Performance
Standard library HashMap
Naive HashMap
Testing with QuickCheck
Testing with American Fuzzy Lop
Performance testing with Criterion
Inspecting with the Valgrind Suite
Inspecting with Linux perf
A better naive HashMap
Summary
Further reading
The Rust Memory Model – Ownership, References and Manipulation
Technical requirements
Memory layout
Pointers to memory
Allocating and deallocating memory
The size of a type
Static and dynamic dispatch
Zero sized types
Boxed types
Custom allocators
Implementations
Option
Cell and RefCell
Rc
Vec
Summary
Further reading
Sync and Send – the Foundation of Rust Concurrency
Technical requirements
Sync and Send
Racing threads
The flaw of the Ring
Getting back to safety
Safety by exclusion
Using MPSC
A telemetry server
Summary
Further reading
Locks – Mutex, Condvar, Barriers and RWLock
Technical requirements
Read many, write exclusive locks – RwLock
Blocking until conditions change – condvar
Blocking until the gang's all here - barrier
More mutexes, condvars, and friends in action
The rocket preparation problem
The rope bridge problem
Hopper—an MPSC specialization
The problem
Hopper in use
A conceptual view of hopper
The deque
The Receiver
The Sender
Testing concurrent data structures
QuickCheck and loops
Searching for crashes with AFL
Benchmarking
Summary
Further reading
Atomics – the Primitives of Synchronization
Technical requirements
Linearizability
Memory ordering – happens-before and synchronizes-with
Ordering::Relaxed
Ordering::Acquire
Ordering::Release
Ordering::AcqRel
Ordering::SeqCst
Building synchronization
Mutexes
Compare and set mutex
An incorrect atomic queue
Options to correct the incorrect queue
Semaphore
Binary semaphore, or, a less wasteful mutex
Summary
Further reading
Atomics – Safely Reclaiming Memory
Technical requirements
Approaches to memory reclamation
Reference counting
Tradeoffs
Hazard pointers
A hazard-pointer Treiber stack
The hazard of Nightly
Exercizing the hazard-pointer Treiber stack
Tradeoffs
Epoch-based reclamation
An epoch-based Treiber stack
crossbeam_epoch::Atomic
crossbeam_epoch::Guard::defer
crossbeam_epoch::Local::pin
Exercising the epoch-based Treiber stack
Tradeoffs
Summary
Further reading
High-Level Parallelism – Threadpools, Parallel Iterators and Processes
Technical requirements
Thread pooling
Slowloris – attacking thread-per-connection servers
The server
The client
A thread-pooling server
Looking into thread pool
The Ethernet sniffer
Iterators
Smallcheck iteration
rayon – parallel iterators
Data parallelism and OS processes – evolving corewars players
Corewars
Feruscore – a Corewars evolver
Representing the domain
Exploring the source
Instructions
Individuals
Mutation and reproduction
Competition – calling out to pMARS
Main
Running feruscore
Summary
Further reading
FFI and Embedding – Combining Rust and Other Languages
Embedding C into Rust – feruscore without processes
The MARS C interface
Creating C-structs from Rust
Calling C functions
Managing cross-language ownership
Running the simulation
Fuzzing the simulation
The feruscore executable
Embedding Lua into Rust
Embedding Rust
Into C
The Rust side
The C side
Into Python
Into Erlang/Elixir
Summary
Further reading
Futurism – Near-Term Rust
Technical requirements
Near-term improvements
SIMD
Hex encoding
Futures and async/await
Specialization
Interesting projects
Fuzzing
Seer, a symbolic execution engine for Rust
The community
Should I use unsafe?
Summary
Further reading
Other Books You May Enjoy
Leave a review - let other readers know what you think
Download from finelybook 7450911@qq.com Hands-On Concurrency with Rust Confidently build memory-safe, parallel, and efficient software in Rust 2
Download from finelybook 7450911@qq.com Brian L. Troutwine 3
Download from finelybook 7450911@qq.com BIRMINGHAM - MUMBAI 4
Download from finelybook 7450911@qq.com Hands-On Concurrency with Rust Copyright © 2018 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. Commissioning Editor: Aaron Lazar Acquisition Editor: Chaitanya Nair Content Development Editor: Akshada Iyer Technical Editor: Mehul Singh Copy Editor: Safis Editing Project Coordinator: Prajakta Naik Proofreader: Safis Editing Indexer: Mariammal Chettiyar Graphics: Jisha Chirayil Production Coordinator: Aparna Bhagat First published: May 2018 Production reference: 1290518 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78839-997-5 www.packtpub.com 5
Download from finelybook 7450911@qq.com For my parents, who taught me how to be. For Hope, with whom life is more joyful than I ever imagined. For Oliver, who was there at the start. He saw what there was to see. 6
Download from finelybook 7450911@qq.com mapt.io Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website. 7
Download from finelybook 7450911@qq.com Why subscribe? Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals Improve your learning with Skill Plans built especially for you Get a free eBook or video every month Mapt is fully searchable Copy and paste, print, and bookmark content 8
分享到:
收藏