mirror of
https://github.com/rust-lang/book.git
synced 2026-11-30 21:41:18 -06:00
Merge pull request #322 from mandeep/data-race-correction
Corrected run-on sentence in data race definition
This commit is contained in:
@@ -155,13 +155,17 @@ error[E0499]: cannot borrow `s` as mutable more than once at a time
|
|||||||
This restriction allows for mutation but in a very controlled fashion. It is
|
This restriction allows for mutation but in a very controlled fashion. It is
|
||||||
something that new Rustaceans struggle with, because most languages let you
|
something that new Rustaceans struggle with, because most languages let you
|
||||||
mutate whenever you’d like. The benefit of having this restriction is that Rust
|
mutate whenever you’d like. The benefit of having this restriction is that Rust
|
||||||
can prevent data races at compile time. A *data race* is a particular type of
|
can prevent data races at compile time.
|
||||||
race condition where two or more pointers access the same data at the same
|
|
||||||
time, at least one of the pointers is being used to write to the data, and
|
A *data race* is a particular type of race condition where these three things occur:
|
||||||
there’s no mechanism being used to synchronize access to the data. Data races
|
|
||||||
cause undefined behavior and can be difficult to diagnose and fix when trying
|
- two or more pointers access the same data at the same time
|
||||||
to track them down at runtime; Rust prevents this problem from happening since
|
- at least one of the pointers is being used to write to the data
|
||||||
it won’t even compile code with data races!
|
- there’s no mechanism being used to synchronize access to the data
|
||||||
|
|
||||||
|
Data races cause undefined behavior and can be difficult to diagnose and fix
|
||||||
|
when trying to track them down at runtime; Rust prevents this problem from
|
||||||
|
happening since it won’t even compile code with data races!
|
||||||
|
|
||||||
As always, we can use `{}`s to create a new scope, allowing for multiple mutable
|
As always, we can use `{}`s to create a new scope, allowing for multiple mutable
|
||||||
references, just not *simultaneous* ones:
|
references, just not *simultaneous* ones:
|
||||||
|
|||||||
Reference in New Issue
Block a user