- InfoQ is a news and community site for software developers with 750,000 unique visitors per month publishing content in 4 languages.
- It posts content from QCon conferences including news, articles, presentations, interviews and books to empower software development through spreading knowledge and innovation.
- QCon conferences are practitioner-driven and designed for influencers of change and innovation, connecting them and catalyzing innovation, and have been attended by over 12,000 delegates since 2007 across 9 cities worldwide.
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/
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
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
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
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
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
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”