SlideShare a Scribd company logo
Aaron Turon	

Mozilla Research
InfoQ.com: News & Community Site
• 750,000 unique visitors/month
• Published in 4 languages (English, Chinese, Japanese and Brazilian
Portuguese)
• Post content from our QCon conferences
• News 15-20 / week
• Articles 3-4 / week
• Presentations (videos) 12-15 / week
• Interviews 2-3 / week
• Books 1 / month
Watch the video with slide
synchronization on InfoQ.com!
http://www.infoq.com/presentations
/rust-thread-safety
Purpose of QCon
- to empower software development by facilitating the spread of
knowledge and innovation
Strategy
- practitioner-driven conference designed for YOU: influencers of
change and innovation in your teams
- speakers and topics driving the evolution and innovation
- connecting and catalyzing the influencers and innovators
Highlights
- attended by more than 12,000 delegates since 2007
- held in 9 cities worldwide
Presented at QCon San Francisco
www.qconsf.com
Rust is a systems programming language
that runs blazingly fast, prevents nearly all
segfaults, and guarantees thread safety. 	

- https://www.rust-lang.org/
Safety
Control
C C++
Go
Java
Haskell
Scala
“Low-level”
Conventional wisdom
The Essence of Rust
Low-level == Unsafe
+ Safe
Why Rust?
- You’re already doing systems programming, 

want safety or expressiveness.	

!
- You wish you could do some systems work	

- Maybe as an embedded piece in your

Java, Python, JS, Ruby, …
Why Mozilla?
Browsers need control.
Browsers need safety.
Servo: Next-generation
browser built in Rust.
Rust: New language for 	

safe systems programming.
What is control?
void example() {
vector<string> vector;
…
auto& elem = vector[0];
…
}
string[0]
…elem
vector
data
length
capacity
[0]
[n]
[…]
…
‘H’
…
‘e’
Stack and inline layout.
Interior references
Deterministic destruction
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, many others.
Ownership & Borrowing
Memory	

safety
Data-race	

freedom	

(and more)
No need for	

a runtime
GCC++
… Plus lots of goodies
- Pattern matching	

- Traits	

- “Smart” pointers	

- Metaprogramming	

- Package management (think Bundler)
TL;DR: Rust is a modern language
Ownership
!
n. The act, state, or right of possessing something.
Ownership (T)
Aliasing Mutation
vec
data
length
capacity
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 aVec<int>
fn give() {
let mut vec = Vec::new();
vec.push(1);
vec.push(2);
take(vec);
…
}
vec.push(2);
Compiler enforces moves
fn take(vec: Vec<int>) {
// …
}
!
!
!Error: vec has been moved
Prevents:	

- use after free	

- double moves	

- …
Borrow
!
v. To receive something with the promise of returning it.
Shared borrow (&T)
Aliasing Mutation
Mutable borrow (&mut T)
Aliasing Mutation
fn lender() {
let mut vec = Vec::new();
vec.push(1);
vec.push(2);
use(&vec);
…
}
fn use(vec: &Vec<int>) {
// …
}
!
!
!
1
2vec
data
length
capacity
vec
“Shared reference	

toVec<int>”
Loan out vec
fn use(vec: &Vec<int>) {
vec.push(3);
vec[1] += 2;
}
Shared references are immutable:
Error: cannot mutate shared reference
* Actually: mutation only in controlled circumstances
*
Aliasing Mutation
fn push_all(from: &Vec<int>, to: &mut Vec<int>) {
for elem in from {
to.push(*elem);
}
}
Mutable references
mutable reference to Vec<int>
push() is legal
1
2
3
from
to
elem
1
…
fn push_all(from: &Vec<int>, to: &mut Vec<int>) {
for elem in from {
to.push(*elem);
}
}
Mutable references
What if from and to are equal?
1
2
3
from
to
elem
1
2
3
…
1
fn push_all(from: &Vec<int>, to: &mut Vec<int>) {
for elem in from {
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 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
Concurrency
!
n. several computations executing simultaneously, and
potentially interacting with each other.
Rust’s vision for concurrency
Originally:	

!
Now:
only isolated message passing
libraries for many paradigms,	

using ownership to avoid footguns,	

guaranteeing no data races
Data race
Two unsynchronized threads	

accessing same data
where at least one writes.
✎
✎
Aliasing
Mutation
No ordering
Data race
Sound familiar?
No data races =	

No accidentally-shared state.	

!
All sharing is explicit!
*some_value = 5;
return *some_value == 5; // ALWAYS true
Messaging
(ownership)
data
length
capacity
data
length
capacity
move || {
let m = Vec::new();
…
tx.send(m);
}
rx
tx
tx
m
fn parent() {
let (tx, rx) = channel();
spawn(move || {…});
let m = rx.recv();
}
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, releasing lock
Disjoint, scoped access
(borrowing)
✎
✎
fn qsort(vec: &mut [int]) {
if vec.len() <= 1 { return; }
let pivot = vec[random(vec.len())];
let mid = vec.partition(vec, pivot);
let (less, greater) = vec.split_at_mut(mid);
qsort(less);
qsort(greater);
}
[0] [1] [2] [3] […] [n]
let vec: &mut [int] = …;
less greater
fn split_at_mut(&mut self, mid: usize)
-> (&mut [T], & mut [T])
[0] [1] [2] [3] […] [n]
let vec: &mut [int] = …;
less greater
fn parallel_qsort(vec: &mut [int]) {
if vec.len() <= 1 { return; }
let pivot = vec[random(vec.len())];
let mid = vec.partition(vec, pivot);
let (less, greater) = vec.split_at_mut(mid);
parallel::join(
|| parallel_qsort(less),
|| parallel_qsort(greater)
);
}
Arc<Vec<int>>: Send
Rc<Vec<int>> : !Send
fn send<T: Send>(&self, t: T)
Only “sendable” types
Static checking for thread safety
And beyond…
Concurrency 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
Unsafe
!
adj. not safe; hazardous
Safe abstractions
unsafe {
…
}
Useful for:	

	

 Bending mutation/aliasing rules (split_at_mut)	

	

 Interfacing with C code
Trust me.
fn something_safe(…) {
!
!
!
!
}
Validates input, etc.
Ownership enables safe abstraction boundaries.
Community
!
n. A feeling of fellowship with others sharing similar goals.
“The Rust community seems to be
populated entirely by human beings.
I have no idea how this was done.”	

— Jamie Brandon
It takes a village…
Community focus from the start:	

	

 Rust 1.0 had > 1,000 contributors	

	

 Welcoming, pragmatic culture	

!
Developed “in the open”	

	

 Much iteration;	

humility is key!	

!
Clear leadership	

	

 Mix of academic and engineering backgrounds	

	

 “Keepers of the vision”
Rust: Unlocking Systems Programming
Memory safety	

Concurrency	

Abstraction	

Stability
without
garbage collection	

data races	

overhead	

stagnation
Hack without fear!
Articulating the vision
Watch the video with slide synchronization on
InfoQ.com!
http://www.infoq.com/presentations/rust-
thread-safety

More Related Content

PDF
Rust: Systems Programming for Everyone
PDF
Rust system programming language
PPTX
Introduction to Rust language programming
PDF
The Rust Programming Language: an Overview
PPT
Rust Programming Language
PDF
An introduction to Rust: the modern programming language to develop safe and ...
PDF
Why rust?
Rust: Systems Programming for Everyone
Rust system programming language
Introduction to Rust language programming
The Rust Programming Language: an Overview
Rust Programming Language
An introduction to Rust: the modern programming language to develop safe and ...
Why rust?

What's hot (20)

PDF
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
PDF
Rust Tutorial | Rust Programming Language Tutorial For Beginners | Rust Train...
ODP
Rust Primer
PPTX
Rust vs C++
PDF
Deep drive into rust programming language
PDF
Docker Security: Are Your Containers Tightly Secured to the Ship?
PPTX
Rust programming-language
PDF
Introduce to Rust-A Powerful System Language
PDF
[오픈소스컨설팅] EFK Stack 소개와 설치 방법
PDF
[오픈소스컨설팅] 쿠버네티스와 쿠버네티스 on 오픈스택 비교 및 구축 방법
PPTX
0x003 - Exploiting LOLDrivers - Physical Memory Mayhem
PPTX
Docker introduction &amp; benefits
PPTX
Write microservice in golang
PPTX
Introduction to Rust (Presentation).pptx
PDF
DevSecOps Jenkins Pipeline -Security
PPTX
What is Docker?
PPT
Docker introduction
PDF
Build Low-Latency Applications in Rust on ScyllaDB
PDF
Intro to Linux Shell Scripting
PDF
HashiCorp's Vault - The Examples
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
Rust Tutorial | Rust Programming Language Tutorial For Beginners | Rust Train...
Rust Primer
Rust vs C++
Deep drive into rust programming language
Docker Security: Are Your Containers Tightly Secured to the Ship?
Rust programming-language
Introduce to Rust-A Powerful System Language
[오픈소스컨설팅] EFK Stack 소개와 설치 방법
[오픈소스컨설팅] 쿠버네티스와 쿠버네티스 on 오픈스택 비교 및 구축 방법
0x003 - Exploiting LOLDrivers - Physical Memory Mayhem
Docker introduction &amp; benefits
Write microservice in golang
Introduction to Rust (Presentation).pptx
DevSecOps Jenkins Pipeline -Security
What is Docker?
Docker introduction
Build Low-Latency Applications in Rust on ScyllaDB
Intro to Linux Shell Scripting
HashiCorp's Vault - The Examples
Ad

Viewers also liked (20)

PPTX
Rust is for Robots!
PDF
Servo: The parallel web engine
PDF
Rust Workshop - NITC FOSSMEET 2017
PDF
Type-Directed TDD in Rust: a case study using FizzBuzz
PPTX
What the &~#@&lt;!? (Memory Management in Rust)
PDF
OOP in Rust
PDF
Machine Learning in Rust with Leaf and Collenchyma
PPTX
Kernel-Level Programming: Entering Ring Naught
PDF
Hey! There's OCaml in my Rust!
PPTX
Ruby is Awesome and Rust is Awesome and Building a Game in Both is AWESOME
PDF
RUSTing -- Partially Ordered Rust Programming Ruminations
PDF
Lessons in failure entrepreneurship is a journey through zeroes
PPTX
Area de tecnologia e imformatica en el instituto
PPTX
Final ppt of financial mgmt
DOCX
Magazine Questionnaire
PDF
Untitled Presentation
PDF
Презентация ПромРезерв (Москва)
PPT
Technology’s role in 21st century learning
PPT
Volunteer Editor Introduction
Rust is for Robots!
Servo: The parallel web engine
Rust Workshop - NITC FOSSMEET 2017
Type-Directed TDD in Rust: a case study using FizzBuzz
What the &~#@&lt;!? (Memory Management in Rust)
OOP in Rust
Machine Learning in Rust with Leaf and Collenchyma
Kernel-Level Programming: Entering Ring Naught
Hey! There's OCaml in my Rust!
Ruby is Awesome and Rust is Awesome and Building a Game in Both is AWESOME
RUSTing -- Partially Ordered Rust Programming Ruminations
Lessons in failure entrepreneurship is a journey through zeroes
Area de tecnologia e imformatica en el instituto
Final ppt of financial mgmt
Magazine Questionnaire
Untitled Presentation
Презентация ПромРезерв (Москва)
Technology’s role in 21st century learning
Volunteer Editor Introduction
Ad

Similar to Rust: Unlocking Systems Programming (20)

PDF
Guaranteeing Memory Safety in Rust
PDF
Rust Intro @ Roma Rust meetup
PDF
Rust "Hot or Not" at Sioux
PDF
C++ references
PDF
Rust: Reach Further
PPTX
Kotlin coroutines and spring framework
PDF
Get Ahead with HTML5 on Moible
PDF
Security in the blockchain
PDF
Embedded Rust on IoT devices
PPTX
5 x HTML5 worth using in APEX (5)
PPT
Qt for S60
PDF
Hacking the Mesh: Extending Istio with WebAssembly Modules | DevNation Tech Talk
PPTX
Return of c++
PDF
Comet with node.js and V8
PPT
TinyOS 2.1 tutorial at IPSN 2009
PDF
Capacity Planning for Linux Systems
PPTX
Node js introduction
PDF
Solving New School with the Old School (Clojure)
PDF
Gateway and secure micro services
PDF
The Art Of Readable Code
Guaranteeing Memory Safety in Rust
Rust Intro @ Roma Rust meetup
Rust "Hot or Not" at Sioux
C++ references
Rust: Reach Further
Kotlin coroutines and spring framework
Get Ahead with HTML5 on Moible
Security in the blockchain
Embedded Rust on IoT devices
5 x HTML5 worth using in APEX (5)
Qt for S60
Hacking the Mesh: Extending Istio with WebAssembly Modules | DevNation Tech Talk
Return of c++
Comet with node.js and V8
TinyOS 2.1 tutorial at IPSN 2009
Capacity Planning for Linux Systems
Node js introduction
Solving New School with the Old School (Clojure)
Gateway and secure micro services
The Art Of Readable Code

More from C4Media (20)

PDF
Streaming a Million Likes/Second: Real-Time Interactions on Live Video
PDF
Next Generation Client APIs in Envoy Mobile
PDF
Software Teams and Teamwork Trends Report Q1 2020
PDF
Understand the Trade-offs Using Compilers for Java Applications
PDF
Kafka Needs No Keeper
PDF
High Performing Teams Act Like Owners
PDF
Does Java Need Inline Types? What Project Valhalla Can Bring to Java
PDF
Service Meshes- The Ultimate Guide
PDF
Shifting Left with Cloud Native CI/CD
PDF
CI/CD for Machine Learning
PDF
Fault Tolerance at Speed
PDF
Architectures That Scale Deep - Regaining Control in Deep Systems
PDF
ML in the Browser: Interactive Experiences with Tensorflow.js
PDF
Build Your Own WebAssembly Compiler
PDF
User & Device Identity for Microservices @ Netflix Scale
PDF
Scaling Patterns for Netflix's Edge
PDF
Make Your Electron App Feel at Home Everywhere
PDF
The Talk You've Been Await-ing For
PDF
Future of Data Engineering
PDF
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
Streaming a Million Likes/Second: Real-Time Interactions on Live Video
Next Generation Client APIs in Envoy Mobile
Software Teams and Teamwork Trends Report Q1 2020
Understand the Trade-offs Using Compilers for Java Applications
Kafka Needs No Keeper
High Performing Teams Act Like Owners
Does Java Need Inline Types? What Project Valhalla Can Bring to Java
Service Meshes- The Ultimate Guide
Shifting Left with Cloud Native CI/CD
CI/CD for Machine Learning
Fault Tolerance at Speed
Architectures That Scale Deep - Regaining Control in Deep Systems
ML in the Browser: Interactive Experiences with Tensorflow.js
Build Your Own WebAssembly Compiler
User & Device Identity for Microservices @ Netflix Scale
Scaling Patterns for Netflix's Edge
Make Your Electron App Feel at Home Everywhere
The Talk You've Been Await-ing For
Future of Data Engineering
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More

Recently uploaded (20)

PDF
Electronic commerce courselecture one. Pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Machine learning based COVID-19 study performance prediction
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
A Presentation on Artificial Intelligence
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Approach and Philosophy of On baking technology
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Chapter 3 Spatial Domain Image Processing.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Electronic commerce courselecture one. Pdf
Spectroscopy.pptx food analysis technology
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Machine learning based COVID-19 study performance prediction
Network Security Unit 5.pdf for BCA BBA.
A Presentation on Artificial Intelligence
Encapsulation_ Review paper, used for researhc scholars
MYSQL Presentation for SQL database connectivity
Dropbox Q2 2025 Financial Results & Investor Presentation
MIND Revenue Release Quarter 2 2025 Press Release
A comparative analysis of optical character recognition models for extracting...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Approach and Philosophy of On baking technology
Digital-Transformation-Roadmap-for-Companies.pptx
Unlocking AI with Model Context Protocol (MCP)
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Empathic Computing: Creating Shared Understanding
Chapter 3 Spatial Domain Image Processing.pdf
The AUB Centre for AI in Media Proposal.docx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf

Rust: Unlocking Systems Programming

  • 2. InfoQ.com: News & Community Site • 750,000 unique visitors/month • Published in 4 languages (English, Chinese, Japanese and Brazilian Portuguese) • Post content from our QCon conferences • News 15-20 / week • Articles 3-4 / week • Presentations (videos) 12-15 / week • Interviews 2-3 / week • Books 1 / month Watch the video with slide synchronization on InfoQ.com! http://www.infoq.com/presentations /rust-thread-safety
  • 3. Purpose of QCon - to empower software development by facilitating the spread of knowledge and innovation Strategy - practitioner-driven conference designed for YOU: influencers of change and innovation in your teams - speakers and topics driving the evolution and innovation - connecting and catalyzing the influencers and innovators Highlights - attended by more than 12,000 delegates since 2007 - held in 9 cities worldwide Presented at QCon San Francisco www.qconsf.com
  • 4. Rust is a systems programming language that runs blazingly fast, prevents nearly all segfaults, and guarantees thread safety. - https://www.rust-lang.org/
  • 6. Conventional wisdom The Essence of Rust Low-level == Unsafe + Safe
  • 7. Why Rust? - You’re already doing systems programming, 
 want safety or expressiveness. ! - You wish you could do some systems work - Maybe as an embedded piece in your
 Java, Python, JS, Ruby, …
  • 8. Why Mozilla? Browsers need control. Browsers need safety. Servo: Next-generation browser built in Rust. Rust: New language for safe systems programming.
  • 9. What is control? void example() { vector<string> vector; … auto& elem = vector[0]; … } string[0] …elem vector data length capacity [0] [n] […] … ‘H’ … ‘e’ Stack and inline layout. Interior references Deterministic destruction Stack Heap C++
  • 10. 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
  • 11. 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.
  • 12. What about GC? No control. Requires a runtime. Insufficient to prevent related problems: iterator invalidation, data races, many others.
  • 14. … Plus lots of goodies - Pattern matching - Traits - “Smart” pointers - Metaprogramming - Package management (think Bundler) TL;DR: Rust is a modern language
  • 15. Ownership ! n. The act, state, or right of possessing something.
  • 17. vec data length capacity 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 aVec<int>
  • 18. fn give() { let mut vec = Vec::new(); vec.push(1); vec.push(2); take(vec); … } vec.push(2); Compiler enforces moves fn take(vec: Vec<int>) { // … } ! ! !Error: vec has been moved Prevents: - use after free - double moves - …
  • 19. Borrow ! v. To receive something with the promise of returning it.
  • 21. Mutable borrow (&mut T) Aliasing Mutation
  • 22. fn lender() { let mut vec = Vec::new(); vec.push(1); vec.push(2); use(&vec); … } fn use(vec: &Vec<int>) { // … } ! ! ! 1 2vec data length capacity vec “Shared reference toVec<int>” Loan out vec
  • 23. fn use(vec: &Vec<int>) { vec.push(3); vec[1] += 2; } Shared references are immutable: Error: cannot mutate shared reference * Actually: mutation only in controlled circumstances * Aliasing Mutation
  • 24. fn push_all(from: &Vec<int>, to: &mut Vec<int>) { for elem in from { to.push(*elem); } } Mutable references mutable reference to Vec<int> push() is legal
  • 25. 1 2 3 from to elem 1 … fn push_all(from: &Vec<int>, to: &mut Vec<int>) { for elem in from { to.push(*elem); } } Mutable references
  • 26. What if from and to are equal? 1 2 3 from to elem 1 2 3 … 1 fn push_all(from: &Vec<int>, to: &mut Vec<int>) { for elem in from { to.push(*elem); } } dangling pointer
  • 27. 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
  • 28. { let mut vec = Vec::new(); … for i in 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
  • 29. Concurrency ! n. several computations executing simultaneously, and potentially interacting with each other.
  • 30. Rust’s vision for concurrency Originally: ! Now: only isolated message passing libraries for many paradigms, using ownership to avoid footguns, guaranteeing no data races
  • 31. Data race Two unsynchronized threads accessing same data where at least one writes. ✎ ✎
  • 33. No data races = No accidentally-shared state. ! All sharing is explicit! *some_value = 5; return *some_value == 5; // ALWAYS true
  • 35. data length capacity data length capacity move || { let m = Vec::new(); … tx.send(m); } rx tx tx m fn parent() { let (tx, rx) = channel(); spawn(move || {…}); let m = rx.recv(); }
  • 36. Locked mutable access (ownership, borrowing) ✎ ✎
  • 37. 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, releasing lock
  • 39. fn qsort(vec: &mut [int]) { if vec.len() <= 1 { return; } let pivot = vec[random(vec.len())]; let mid = vec.partition(vec, pivot); let (less, greater) = vec.split_at_mut(mid); qsort(less); qsort(greater); } [0] [1] [2] [3] […] [n] let vec: &mut [int] = …; less greater
  • 40. fn split_at_mut(&mut self, mid: usize) -> (&mut [T], & mut [T])
  • 41. [0] [1] [2] [3] […] [n] let vec: &mut [int] = …; less greater fn parallel_qsort(vec: &mut [int]) { if vec.len() <= 1 { return; } let pivot = vec[random(vec.len())]; let mid = vec.partition(vec, pivot); let (less, greater) = vec.split_at_mut(mid); parallel::join( || parallel_qsort(less), || parallel_qsort(greater) ); }
  • 42. Arc<Vec<int>>: Send Rc<Vec<int>> : !Send fn send<T: Send>(&self, t: T) Only “sendable” types Static checking for thread safety
  • 43. And beyond… Concurrency 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
  • 45. Safe abstractions unsafe { … } Useful for: Bending mutation/aliasing rules (split_at_mut) Interfacing with C code Trust me. fn something_safe(…) { ! ! ! ! } Validates input, etc. Ownership enables safe abstraction boundaries.
  • 46. Community ! n. A feeling of fellowship with others sharing similar goals.
  • 47. “The Rust community seems to be populated entirely by human beings. I have no idea how this was done.” — Jamie Brandon
  • 48. It takes a village… Community focus from the start: Rust 1.0 had > 1,000 contributors Welcoming, pragmatic culture ! Developed “in the open” Much iteration; humility is key! ! Clear leadership Mix of academic and engineering backgrounds “Keepers of the vision”
  • 50. Memory safety Concurrency Abstraction Stability without garbage collection data races overhead stagnation Hack without fear! Articulating the vision
  • 51. Watch the video with slide synchronization on InfoQ.com! http://www.infoq.com/presentations/rust- thread-safety