3 ms·
Could you give an example of a kind of race conditions allowed in Rust? (Sorry for a naive question, just thought that a data race and a race condition are syn
by GreenWinters 9y ago
Could you give an example of a kind of race conditions allowed in Rust?
(Sorry for a naive question, just thought that a data race and a race condition are synonyms. What else is there to race over if not shared data?)
- dbaupp 9y agoThe "data race" term is jargon (i.e. means more than just "race on data") that specifically refers to unsynchronised concurrent accesses to a piece of memory/resource (where at least one of the accesses is a write), while a race condition is a higher level thing, where things aren't ordered the way one intends, even if they have the appropriate "low-level" synchronisation to avoid data races. http://blog.regehr.org/archives/490 http://blog.regehr.org/archives/490 Rust can't prevent one from doing all the right low-level synchronisation in the wrong order. In fact, I don't think any language can, without somehow being able to understand the spec of a program: something that's a race condition in one case, may not be a race condition elsewhere (this differs to a data race, which isn't context dependent).
- leshow 9y agoRust does not prevent all race conditions because doing so would be impossible. It would be akin to solving the halting problem. Deadlocks, and other synchronization issues are just some 'general race conditions' Rust can't solve. Rust's prevents 'data races' defined as: -two or more threads concurrently accessing a location of memory -one of them is a write -one of them is unsynchronized https://doc.rust-lang.org/nomicon/races.html https://doc.rust-lang.org/nomicon/races.html