SlideShare a Scribd company logo
Rust 
Nicholas Matsakis 
Mozilla Research
What makes Rust different? 
C++ 
Haskell 
Java 
ML 
More Control More Safety 
Rust: Control and safety
Why Mozilla? 
Browsers need control. 
Browsers need safety. 
Servo: Next-generation 
browser built in Rust.
What is control? 
void example() { 
vector<string> vector; 
… 
auto& elem = vector[0]; 
… 
} 
Stack and inline layout. 
Lightweight references 
Deterministic destruction 
[0] 
string 
el…em 
vector 
data 
length 
capacity 
[…] 
[n] 
… 
‘H’ 
‘e’ 
… 
Stack Heap 
C++
Zero-cost abstraction 
Ability to define abstractions that 
optimize away to nothing. 
vector data 
length 
cap. 
[0] 
[…] 
data cap. 
‘H’ 
‘e’ 
[…] 
Not just memory layout: 
- Static dispatch 
- Template expansion 
- … Java
What is safety? 
void example() { 
vector<string> vector; 
… 
auto& elem = vector[0]; 
vector.push_back(some_string); 
cout << elem; 
} 
vector 
data 
length 
capacity 
[0] 
… 
[0] 
[1] 
elem 
Aliasing: more than 
one pointer to same 
memory. 
Dangling pointer: pointer 
to freed memory. 
C++ 
Mutating the vector 
freed old contents.
What about GC? 
No control. 
Requires a runtime. 
Insufficient to prevent related problems: 
iterator invalidation, data races.
void foo(Foo &&f, …) { 
vec.push_back(f); 
} 
C++ 
Gut it: 
void foo(const Foo &f, …) { 
use(f.bar); 
} 
Read it: 
void foo(Foo &f, …) { 
f.bar = …; 
} 
Write it: 
void foo(unique_ptr<Foo> f, …) { 
… 
} 
Keep it:
Definitely progress. 
! 
But definitely not safe: 
! 
- Iterator invalidation. 
- Double moves. 
- Pointers into stack or freed memory. 
- Data races. 
- … all that stuff I talked about before … 
! 
Ultimately, C++ mechanisms are unenforced.
The Rust Solution 
Codify and enforce safe patterns 
using the type system: 
! 
1. Always have a clear owner. 
2. While iterating over a vector, 
don’t change it. 
3. … 
! 
No runtime required.
Credit where it is due 
Rust borrows liberally from other great languages: 
C++, Haskell, ML/Ocaml, Cyclone, 
Erlang, Java, C#, … 
Rust has an active, amazing community. 
❤
The Rust type system
Observation 
Danger arises from… 
Aliasing Mutation 
Hides dependencies. Causes memory 
to be freed. 
{ auto& e = v[0]; … v.push_back(…); }
Three basic patterns 
fn foo(v: T) { 
… 
} 
Ownership 
fn foo(v: &T) { 
… 
} 
Shared borrow 
fn foo(v: &mut T) { 
… 
} 
Mutable borrow
Ownership! 
! 
n. The act, state, or right of possessing something.
Aliasing Mutation 
Ownership (T)
vec 
data 
length 
capacity 
1 
2 
fn give() { 
let mut vec = Vec::new(); 
vec.push(1); 
vec.push(2); 
take(vec); 
… 
} 
fn take(vec: Vec<int>) { 
// … 
} 
! 
Take ownership 
! 
of a Vec<int> 
!
Compiler enforces moves 
fn give() { 
let mut vec = Vec::new(); 
vec.push(1); 
vec.push(2); 
take(vec); 
vec.… 
push(2); 
} 
fn take(vec: Vec<int>) { 
// … 
} 
! 
! 
Error: ve! c has been moved 
Prevents: 
- use after free 
- double moves 
- …
Borrow! 
! 
v. To receive something with the promise of returning it.
Aliasing Mutation 
Shared borrow (&T)
Aliasing Mutation 
Mutable borrow (&mut T)
fn lender() { 
let mut vec = Vec::new(); 
vec.push(1); 
vec.push(2); 
use(&vec); 
… 
} 
fn use(vec: &Vec<int>) { 
// … 
} 
! 
! 
! 
1 
data 
length 
capacity 
vec 2 
vec 
“Shared reference 
to Vec<int>” 
Loan out vec
fn dot_product(vec1: &Vec<int>, vec2: &Vec<int>) 
elem1 
elem2 
sum 
-> int { 
let mut sum = 0; 
for (elem1, elem2) in vec1.iter().zip(vec2.iter()) { 
sum += (*elem1) * (*elem2); 
} 
return sum; 
} walk down matching indices 
elem1, elem2 are references into the vector 
1 
2 
3 
4 
5 
6 
* 
vec1 vec2
Why “shared” reference? 
fn dot_product(vec1: &Vec<int>, vec2: &Vec<int>) 
-> int 
{…} 
! 
fn magnitude(vec: &Vec<int>) -> int { 
sqrt(dot_product(vec, vec)) 
} 
two shared references to the 
same vector — OK!
Aliasing Mutation 
Shared references are immutable: 
fn use(vec: &Vec<int>) { 
vec.push(3); 
vec[1] += 2; 
} 
* 
Error: cannot mutate shared reference 
* Actually: mutation only in controlled circumstances
Mutable references 
fn push_all(from: &Vec<int>, to: &mut Vec<int>) { 
for elem in from.iter() { 
to.push(*elem); 
} 
} 
mutable reference to Vec<int> 
push() is legal
Mutable references 
fn push_all(from: &Vec<int>, to: &mut Vec<int>) { 
for elem in from.iter() { 
1 
2 
3 
to.push(*elem); 
} 
} 
from 
to 
elem 
1 
2 
3 
…
What if from and to are equal? 
fn push_all(from: &Vec<int>, to: &mut Vec<int>) { 
for elem in from.iter() { 
1 
2 
3 
from 
to 
elem 
1 
2 
3 
… 
1 
to.push(*elem); 
} 
} dangling pointer
fn push_all(from: &Vec<int>, to: &mut Vec<int>) {…} 
! 
fn caller() { 
let mut vec = …; 
push_all(&vec, &mut vec); 
} 
shared reference 
Error: cannot have both shared 
and mutable reference at same 
time 
A &mut T is the only way to access 
the memory it points at
{ 
let mut vec = Vec::new(); 
… 
for i in range(0, vec.len()) { 
let elem: &int = &vec[i]; 
… 
vec.push(…); 
} 
… 
vec.push(…); 
} 
Borrows restrict access to 
the original path for their 
duration. 
Error: vec[i] is borrowed, 
cannot mutate 
OK. loan expired. 
& 
&mut 
no writes, no moves 
no access at all
Abstraction! 
! 
n. freedom from representational qualities in art.
Rust is an extensible language 
• Zero-cost abstraction 
• Rich libraries: 
- Containers 
- Memory management 
- Parallelism 
- … 
• Ownership and borrowing 
let libraries enforce safety.
fn example() { 
let x: Rc<T> = Rc::new(…); 
{ 
let y = x.clone(); 
let z = &*y; 
… 
} // runs destructor for y 
} // runs destructor for x 
x 1 
[0] 
y 
2 1 
… 
z 
Stack Heap
Borrowing and Rc 
fn deref<‘a,T>(r: &’a Rc<T>) -> &’a T { 
… 
} 
Given a borrowed reference 
to an `Rc<T>`… 
…return a reference to the 
`T` inside with same extent 
New reference can be thought of as a kind of sublease. 
Returned reference cannot outlast the original.
fn example() -> &T { 
let x: Rc<T> = Rc::new(…); 
return &*x; 
} // runs destructor for x 
Error: extent of borrow 
exceeds lifetime of `x`
Concurrency! 
! 
n. several computations executing simultaneously, and 
potentially interacting with each other
Data race 
✎ 
✎ 
✎ 
✎ 
Two unsynchronized threads 
accessing same data! 
where at least one writes.
Aliasing 
Mutation 
No ordering 
Data race 
Sound familiar?
Messaging! 
(ownership)
data 
length 
capacity 
fn parent() { 
let (tx, rx) = channel(); 
spawn(proc() {…}); 
let m = rx.recv(); 
} 
proc() { 
let m = Vec::new(); 
… 
tx.send(m); 
} 
rx 
tx 
tx 
m
Shared read-only access! 
(ownership, borrowing)
Arc<Vec<int>> 
(ARC = Atomic Reference Count) 
Owned, so no aliases. Vec<int> 
&Vec<int> 
ref_count 
data 
length 
capacity 
[0] 
[1] 
Shared reference, so 
Vec<int> is immutable.
✎ 
✎ 
Locked mutable access! 
(ownership, borrowing)
fn sync_inc(mutex: &Mutex<int>) { 
let mut data = mutex.lock(); 
*data += 1; 
} 
Destructor releases lock 
Yields a mutable reference to data 
Destructor runs here
And beyond… 
Parallelism is an area of active development. 
! 
Either already have or have plans for: 
- Atomic primitives 
- Non-blocking queues 
- Concurrent hashtables 
- Lightweight thread pools 
- Futures 
- CILK-style fork-join concurrency 
- etc. 
Always data-race free
Parallel! 
! 
adj. occurring or existing at the same time
Concurrent vs parallel 
Blocks 
Concurrent threads Parallel jobs
fn qsort(vec: &mut [int]) { 
let pivot = vec[random(vec.len())]; 
let mid = vec.partition(vec, pivot); 
let (less, greater) = vec.mut_split_at(mid); 
qsort(less); 
qsort(greater); 
} 
let vec: &mut [int] = …; 
[0] [1] [2] [3] […] [n] 
less greater
fn parallel_qsort(vec: &mut [int]) { 
let pivot = vec[random(vec.len())]; 
let mid = vec.partition(vec, pivot); 
let (less, greater) = vec.mut_split(mid); 
parallel::do(&[ 
|| parallel_qsort(less), 
|| parallel_qsort(greater) 
]); 
} 
let vec: &mut [int] = …; 
[0] [1] [2] [3] […] [n] 
less greater
Unsafe! 
! 
adj. not safe; hazardous
Safe abstractions 
fn something_safe(…) { 
! 
unsafe { 
! 
… 
! 
} 
! 
} 
Validates input, etc. 
Trust me. 
• Uninitialized memory 
• Interfacing with C code 
• Building parallel abstractions like ARC 
• …
Status of Rust 
“Rapidly stabilizing.”! 
! 
! 
Goal for 1.0: 
- Stable syntax, core type system 
- Minimal set of core libraries
Conclusions 
• Rust gives control without compromising safety: 
• Zero-cost abstractions 
• Zero-cost safety 
• Guarantees beyond dangling pointers: 
• Iterator invalidation in a broader sense 
• Data race freedom

More Related Content

PPT
Rust Programming Language
PDF
Introduce to Rust-A Powerful System Language
PDF
Introduction into ES6 JavaScript.
PPT
What Is Php
 
PPTX
.Net Core
PPTX
Java script basics
PDF
Git flow for daily use
PDF
Pointers & References in C++
Rust Programming Language
Introduce to Rust-A Powerful System Language
Introduction into ES6 JavaScript.
What Is Php
 
.Net Core
Java script basics
Git flow for daily use
Pointers & References in C++

What's hot (20)

PDF
Angular - Chapter 4 - Data and Event Handling
PPTX
Css box-model
PPTX
Html Study Guide
PDF
Modern c++ (C++ 11/14)
PDF
JavaScript: Variables and Functions
PPTX
PPTX
Operators and expression in c#
PDF
Web front end development introduction to html css and javascript
PPT
Formatted input and output
PDF
Angular Observables & RxJS Introduction
PPTX
What are variables and keywords in c++
PDF
FOSDEM 2017: GitLab CI
PPTX
The CSS Box Model
PDF
Loom Virtual Threads in the JDK 19
PPTX
Rust vs C++
PDF
Angular 2 observables
PPT
Functions in C++
PPTX
Javascript functions
PDF
Html for beginners
Angular - Chapter 4 - Data and Event Handling
Css box-model
Html Study Guide
Modern c++ (C++ 11/14)
JavaScript: Variables and Functions
Operators and expression in c#
Web front end development introduction to html css and javascript
Formatted input and output
Angular Observables & RxJS Introduction
What are variables and keywords in c++
FOSDEM 2017: GitLab CI
The CSS Box Model
Loom Virtual Threads in the JDK 19
Rust vs C++
Angular 2 observables
Functions in C++
Javascript functions
Html for beginners
Ad

Viewers also liked (7)

PDF
Rust Mozlando Tutorial
PDF
Rust concurrency tutorial 2015 12-02
PDF
Rust tutorial from Boston Meetup 2015-07-22
PDF
Intro to Rust from Applicative / NY Meetup
PDF
Rust system programming language
PDF
Introduction to Rust Programming Language
Rust Mozlando Tutorial
Rust concurrency tutorial 2015 12-02
Rust tutorial from Boston Meetup 2015-07-22
Intro to Rust from Applicative / NY Meetup
Rust system programming language
Introduction to Rust Programming Language
Ad

Similar to Guaranteeing Memory Safety in Rust (20)

PDF
Rust: Unlocking Systems Programming
PDF
Rust "Hot or Not" at Sioux
PDF
Rust Intro @ Roma Rust meetup
PPT
Clojure concurrency
ODP
Getting started with Clojure
PDF
An introduction to Rust: the modern programming language to develop safe and ...
PPTX
Kotlin coroutines and spring framework
PDF
A Survey of Concurrency Constructs
PDF
Clojure 1.1 And Beyond
PDF
scalar.pdf
PDF
Pune Clojure Course Outline
PDF
C++ references
PPT
Java concurrency
PDF
Rust: Reach Further
KEY
Clojure Intro
PPT
Os Reindersfinal
PPT
Os Reindersfinal
PDF
Леонид Шевцов «Clojure в деле»
PDF
Options and trade offs for parallelism and concurrency in Modern C++
ODP
Multithreading Concepts
Rust: Unlocking Systems Programming
Rust "Hot or Not" at Sioux
Rust Intro @ Roma Rust meetup
Clojure concurrency
Getting started with Clojure
An introduction to Rust: the modern programming language to develop safe and ...
Kotlin coroutines and spring framework
A Survey of Concurrency Constructs
Clojure 1.1 And Beyond
scalar.pdf
Pune Clojure Course Outline
C++ references
Java concurrency
Rust: Reach Further
Clojure Intro
Os Reindersfinal
Os Reindersfinal
Леонид Шевцов «Clojure в деле»
Options and trade offs for parallelism and concurrency in Modern C++
Multithreading Concepts

Recently uploaded (20)

PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
PDF
Salesforce Agentforce AI Implementation.pdf
PPTX
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
PPTX
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
PPTX
Trending Python Topics for Data Visualization in 2025
PDF
AI/ML Infra Meetup | Beyond S3's Basics: Architecting for AI-Native Data Access
PDF
How Tridens DevSecOps Ensures Compliance, Security, and Agility
PPTX
Oracle Fusion HCM Cloud Demo for Beginners
PDF
Top 10 Software Development Trends to Watch in 2025 🚀.pdf
PDF
Time Tracking Features That Teams and Organizations Actually Need
PDF
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
PDF
Topaz Photo AI Crack New Download (Latest 2025)
PPTX
Weekly report ppt - harsh dattuprasad patel.pptx
PDF
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
PDF
Wondershare Recoverit Full Crack New Version (Latest 2025)
PPTX
Advanced SystemCare Ultimate Crack + Portable (2025)
PDF
Digital Systems & Binary Numbers (comprehensive )
PPTX
Custom Software Development Services.pptx.pptx
PDF
iTop VPN Crack Latest Version Full Key 2025
wealthsignaloriginal-com-DS-text-... (1).pdf
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
Salesforce Agentforce AI Implementation.pdf
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
Trending Python Topics for Data Visualization in 2025
AI/ML Infra Meetup | Beyond S3's Basics: Architecting for AI-Native Data Access
How Tridens DevSecOps Ensures Compliance, Security, and Agility
Oracle Fusion HCM Cloud Demo for Beginners
Top 10 Software Development Trends to Watch in 2025 🚀.pdf
Time Tracking Features That Teams and Organizations Actually Need
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
Topaz Photo AI Crack New Download (Latest 2025)
Weekly report ppt - harsh dattuprasad patel.pptx
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
Wondershare Recoverit Full Crack New Version (Latest 2025)
Advanced SystemCare Ultimate Crack + Portable (2025)
Digital Systems & Binary Numbers (comprehensive )
Custom Software Development Services.pptx.pptx
iTop VPN Crack Latest Version Full Key 2025

Guaranteeing Memory Safety in Rust

  • 1. Rust Nicholas Matsakis Mozilla Research
  • 2. What makes Rust different? C++ Haskell Java ML More Control More Safety Rust: Control and safety
  • 3. Why Mozilla? Browsers need control. Browsers need safety. Servo: Next-generation browser built in Rust.
  • 4. What is control? void example() { vector<string> vector; … auto& elem = vector[0]; … } Stack and inline layout. Lightweight references Deterministic destruction [0] string el…em vector data length capacity […] [n] … ‘H’ ‘e’ … Stack Heap C++
  • 5. Zero-cost abstraction Ability to define abstractions that optimize away to nothing. vector data length cap. [0] […] data cap. ‘H’ ‘e’ […] Not just memory layout: - Static dispatch - Template expansion - … Java
  • 6. What is safety? void example() { vector<string> vector; … auto& elem = vector[0]; vector.push_back(some_string); cout << elem; } vector data length capacity [0] … [0] [1] elem Aliasing: more than one pointer to same memory. Dangling pointer: pointer to freed memory. C++ Mutating the vector freed old contents.
  • 7. What about GC? No control. Requires a runtime. Insufficient to prevent related problems: iterator invalidation, data races.
  • 8. void foo(Foo &&f, …) { vec.push_back(f); } C++ Gut it: void foo(const Foo &f, …) { use(f.bar); } Read it: void foo(Foo &f, …) { f.bar = …; } Write it: void foo(unique_ptr<Foo> f, …) { … } Keep it:
  • 9. Definitely progress. ! But definitely not safe: ! - Iterator invalidation. - Double moves. - Pointers into stack or freed memory. - Data races. - … all that stuff I talked about before … ! Ultimately, C++ mechanisms are unenforced.
  • 10. The Rust Solution Codify and enforce safe patterns using the type system: ! 1. Always have a clear owner. 2. While iterating over a vector, don’t change it. 3. … ! No runtime required.
  • 11. Credit where it is due Rust borrows liberally from other great languages: C++, Haskell, ML/Ocaml, Cyclone, Erlang, Java, C#, … Rust has an active, amazing community. ❤
  • 12. The Rust type system
  • 13. Observation Danger arises from… Aliasing Mutation Hides dependencies. Causes memory to be freed. { auto& e = v[0]; … v.push_back(…); }
  • 14. Three basic patterns fn foo(v: T) { … } Ownership fn foo(v: &T) { … } Shared borrow fn foo(v: &mut T) { … } Mutable borrow
  • 15. Ownership! ! n. The act, state, or right of possessing something.
  • 17. vec data length capacity 1 2 fn give() { let mut vec = Vec::new(); vec.push(1); vec.push(2); take(vec); … } fn take(vec: Vec<int>) { // … } ! Take ownership ! of a Vec<int> !
  • 18. Compiler enforces moves fn give() { let mut vec = Vec::new(); vec.push(1); vec.push(2); take(vec); vec.… push(2); } fn take(vec: Vec<int>) { // … } ! ! Error: ve! c has been moved Prevents: - use after free - double moves - …
  • 19. Borrow! ! v. To receive something with the promise of returning it.
  • 21. Aliasing Mutation Mutable borrow (&mut T)
  • 22. fn lender() { let mut vec = Vec::new(); vec.push(1); vec.push(2); use(&vec); … } fn use(vec: &Vec<int>) { // … } ! ! ! 1 data length capacity vec 2 vec “Shared reference to Vec<int>” Loan out vec
  • 23. fn dot_product(vec1: &Vec<int>, vec2: &Vec<int>) elem1 elem2 sum -> int { let mut sum = 0; for (elem1, elem2) in vec1.iter().zip(vec2.iter()) { sum += (*elem1) * (*elem2); } return sum; } walk down matching indices elem1, elem2 are references into the vector 1 2 3 4 5 6 * vec1 vec2
  • 24. Why “shared” reference? fn dot_product(vec1: &Vec<int>, vec2: &Vec<int>) -> int {…} ! fn magnitude(vec: &Vec<int>) -> int { sqrt(dot_product(vec, vec)) } two shared references to the same vector — OK!
  • 25. Aliasing Mutation Shared references are immutable: fn use(vec: &Vec<int>) { vec.push(3); vec[1] += 2; } * Error: cannot mutate shared reference * Actually: mutation only in controlled circumstances
  • 26. Mutable references fn push_all(from: &Vec<int>, to: &mut Vec<int>) { for elem in from.iter() { to.push(*elem); } } mutable reference to Vec<int> push() is legal
  • 27. Mutable references fn push_all(from: &Vec<int>, to: &mut Vec<int>) { for elem in from.iter() { 1 2 3 to.push(*elem); } } from to elem 1 2 3 …
  • 28. What if from and to are equal? fn push_all(from: &Vec<int>, to: &mut Vec<int>) { for elem in from.iter() { 1 2 3 from to elem 1 2 3 … 1 to.push(*elem); } } dangling pointer
  • 29. fn push_all(from: &Vec<int>, to: &mut Vec<int>) {…} ! fn caller() { let mut vec = …; push_all(&vec, &mut vec); } shared reference Error: cannot have both shared and mutable reference at same time A &mut T is the only way to access the memory it points at
  • 30. { let mut vec = Vec::new(); … for i in range(0, vec.len()) { let elem: &int = &vec[i]; … vec.push(…); } … vec.push(…); } Borrows restrict access to the original path for their duration. Error: vec[i] is borrowed, cannot mutate OK. loan expired. & &mut no writes, no moves no access at all
  • 31. Abstraction! ! n. freedom from representational qualities in art.
  • 32. Rust is an extensible language • Zero-cost abstraction • Rich libraries: - Containers - Memory management - Parallelism - … • Ownership and borrowing let libraries enforce safety.
  • 33. fn example() { let x: Rc<T> = Rc::new(…); { let y = x.clone(); let z = &*y; … } // runs destructor for y } // runs destructor for x x 1 [0] y 2 1 … z Stack Heap
  • 34. Borrowing and Rc fn deref<‘a,T>(r: &’a Rc<T>) -> &’a T { … } Given a borrowed reference to an `Rc<T>`… …return a reference to the `T` inside with same extent New reference can be thought of as a kind of sublease. Returned reference cannot outlast the original.
  • 35. fn example() -> &T { let x: Rc<T> = Rc::new(…); return &*x; } // runs destructor for x Error: extent of borrow exceeds lifetime of `x`
  • 36. Concurrency! ! n. several computations executing simultaneously, and potentially interacting with each other
  • 37. Data race ✎ ✎ ✎ ✎ Two unsynchronized threads accessing same data! where at least one writes.
  • 38. Aliasing Mutation No ordering Data race Sound familiar?
  • 40. data length capacity fn parent() { let (tx, rx) = channel(); spawn(proc() {…}); let m = rx.recv(); } proc() { let m = Vec::new(); … tx.send(m); } rx tx tx m
  • 41. Shared read-only access! (ownership, borrowing)
  • 42. Arc<Vec<int>> (ARC = Atomic Reference Count) Owned, so no aliases. Vec<int> &Vec<int> ref_count data length capacity [0] [1] Shared reference, so Vec<int> is immutable.
  • 43. ✎ ✎ Locked mutable access! (ownership, borrowing)
  • 44. fn sync_inc(mutex: &Mutex<int>) { let mut data = mutex.lock(); *data += 1; } Destructor releases lock Yields a mutable reference to data Destructor runs here
  • 45. And beyond… Parallelism is an area of active development. ! Either already have or have plans for: - Atomic primitives - Non-blocking queues - Concurrent hashtables - Lightweight thread pools - Futures - CILK-style fork-join concurrency - etc. Always data-race free
  • 46. Parallel! ! adj. occurring or existing at the same time
  • 47. Concurrent vs parallel Blocks Concurrent threads Parallel jobs
  • 48. fn qsort(vec: &mut [int]) { let pivot = vec[random(vec.len())]; let mid = vec.partition(vec, pivot); let (less, greater) = vec.mut_split_at(mid); qsort(less); qsort(greater); } let vec: &mut [int] = …; [0] [1] [2] [3] […] [n] less greater
  • 49. fn parallel_qsort(vec: &mut [int]) { let pivot = vec[random(vec.len())]; let mid = vec.partition(vec, pivot); let (less, greater) = vec.mut_split(mid); parallel::do(&[ || parallel_qsort(less), || parallel_qsort(greater) ]); } let vec: &mut [int] = …; [0] [1] [2] [3] […] [n] less greater
  • 50. Unsafe! ! adj. not safe; hazardous
  • 51. Safe abstractions fn something_safe(…) { ! unsafe { ! … ! } ! } Validates input, etc. Trust me. • Uninitialized memory • Interfacing with C code • Building parallel abstractions like ARC • …
  • 52. Status of Rust “Rapidly stabilizing.”! ! ! Goal for 1.0: - Stable syntax, core type system - Minimal set of core libraries
  • 53. Conclusions • Rust gives control without compromising safety: • Zero-cost abstractions • Zero-cost safety • Guarantees beyond dangling pointers: • Iterator invalidation in a broader sense • Data race freedom