From f905beabf45752b42bc40aee84a2a2d1f745fd8c Mon Sep 17 00:00:00 2001 From: mandeepbhutani Date: Sun, 6 Nov 2016 00:00:55 -0500 Subject: [PATCH 1/2] Corrected run-on sentence in data race definition --- src/ch04-02-references-and-borrowing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch04-02-references-and-borrowing.md b/src/ch04-02-references-and-borrowing.md index 598b7b7d2..4360fc5b9 100644 --- a/src/ch04-02-references-and-borrowing.md +++ b/src/ch04-02-references-and-borrowing.md @@ -157,7 +157,7 @@ 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 can prevent data races at compile time. A *data race* is a particular type of 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 +time. At least one of the pointers is being used to write to the data, and 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 From f3bf6ebd0228f9e4274fbd237717dae4fad40529 Mon Sep 17 00:00:00 2001 From: mandeep Date: Tue, 8 Nov 2016 16:04:56 -0600 Subject: [PATCH 2/2] Separated data race definition into bulleted list --- src/ch04-02-references-and-borrowing.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/ch04-02-references-and-borrowing.md b/src/ch04-02-references-and-borrowing.md index 4360fc5b9..7e0ceecb1 100644 --- a/src/ch04-02-references-and-borrowing.md +++ b/src/ch04-02-references-and-borrowing.md @@ -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 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 -can prevent data races at compile time. A *data race* is a particular type of -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 -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! +can prevent data races at compile time. + +A *data race* is a particular type of race condition where these three things occur: + +- 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 +- 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 references, just not *simultaneous* ones: