3 ms·
Safe Rust prevents data races, but not race conditions in general.
by jrpelkonen 2y ago
Safe Rust prevents data races, but not race conditions in general.
- CryZe 2y agoThough arguably, the fact that in order to mutate data from multiple threads, the compiler,forces you to use some synchronization primitive, results in you having to think about how you are going to synchronize access, which should lower the chance of race condition bugs overall.
- tialaramex 2y agoThe analogy I find helpful for this is, you let the cat out your front door and close it. You walk to the back door and close that too. A race condition (which safe Rust can have) is a normal phenemenon in our world. If we put the cat out the front door, then walk to the kitchen and close that door by the time we reached the back door maybe the cat had run around the outside of the building and come inside again, closing the doors in the wrong order introduced the opportunity for a race - be very careful. A data race (which safe Rust does not have) is a weird thing caused by the mismatch between how you think the computer works and how it actually works. What happens if Alice tries the put the cat out the front door at the same time Bob tries to put it out the back door? Well, in the real world that cannot happen, either Alice has the cat or Bob does. But for many languages† this sort of nonsense can happen and when it does that's a disaster † In safe Rust it can't happen, in Java, OCaml and Go it can happen, but it may not be a disaster (the details are different for each, it is a bug though).
- irundebian 2y agoInteresting analogy.
- aaomidi 2y agoThat’s why I said inside rust. If you bring in external factors then of course it can/will happen.