Skip to content

Commit da6c23a

Browse files
committed
Swap generic quote for one on the danger of data races
1 parent 27de194 commit da6c23a

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

  • content/blog/rust-prevents-data-races-not-race-conditions

content/blog/rust-prevents-data-races-not-race-conditions/index.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ This matters because a data race is [Undefined Behavior](https://doc.rust-lang.o
3434
A data race does not mean you might read a "stale" value.
3535
It means the compiler is allowed to do anything like tear a write in half and reorder it.
3636

37+
And you can't wave this away as a harmless race that happens to work out. As Raph Levien notes in [With undefined behavior, anything is possible](https://raphlinus.github.io/programming/rust/2018/08/17/undefined-behavior.html):
38+
39+
> It used to be thought that data races could be classified into "benign" and dangerous categories, but research strongly suggests that the former category doesn't exist.
40+
41+
In other words, every data race is a real bug!
42+
And because it's Undefined Behavior, the symptom can show up far away from the cause and much later,
43+
in the form of a corrupted value, a crash, or a security hole that only appears under heavy load.
44+
3745
For example, here are two threads incrementing the same counter:
3846

3947
```rust
@@ -112,10 +120,6 @@ The compiler enforces this through two marker traits, [`Send`](https://doc.rust-
112120

113121
That's the whole idea. Rust pushes the locking checks from runtime into the type system.
114122

115-
That guarantee holds up in production. Vivek Bagaria, whose team writes their entire robotics autonomy stack in Rust at [Matic](https://maticrobots.com/), put it this way in an [interview](https://filtra.io/rust/interviews/matic-apr-25):
116-
117-
> Rust is built for fearless concurrency, and it achieves it! Data races are basically impossible unless you are actively trying to shoot yourself in the foot.
118-
119123
{% info(title="Key takeaways") %}
120124

121125
- Synchronized access is not a data race, so it's allowed.

0 commit comments

Comments
 (0)