5 ms·
Rust doesn't magically fix resources contention. It just provides safe concurrency primitives (and the surrounding language semantics) that make it difficult -t
by smaddox 8y ago
Rust doesn't magically fix resources contention. It just provides safe concurrency primitives (and the surrounding language semantics) that make it difficult
-to-impossible to misuse in such a way as to cause a deadlock or race condition.
- phkahler 8y agoRight, so if the language forces you to eliminate deadlocks and race conditions you may find less need for spinlocks which are the problem here. Speculation on my part. I'm not actually advocating Rust but I am thinking about a project to give it a try.
- ehsanu1 8y agoif the language forces you to eliminate deadlocks and race conditions It does not, it only prevents a specific problem known as a data race, which is an issue related to memory/ownership. There is no deadlock protection. And race conditions are a much broader set of issues than just data races. I like rust, just want to keep your expectations in check.
- lunchbreak 8y agoIf I remember correctly, rust doesn't help with deadlocks - you still have to be careful of them. Though it does have primitives to help significantly with race conditions
- bonzini 8y agoThe primitives help with taking the same lock around every access to a location. They don't help in finding locations that should use the same lock; you can easily write Rust code that uses too many separate locks and as such can still have race conditions.
- coldseattle 8y agoIt's amusing to see the Rust astroturfers jump in to any and all threads on hackernews spreading the gospel.
- detaro 8y ago> While I'm skeptical of those claims, That looks like astroturfing to you? Please don't throw accusations like this around willy-nilly.
- deleted 8y ago[deleted]
- phkahler 8y ago>> That looks like astroturfing to you? No, it looks like people exaggerating to me. I don't doubt there is some merit to the safety claims made about Rust, but many people have a tendency toward unwarranted idealization. I admitted that I have not learned Rust yet which should add doubt to my own skepticism. The project I'm thinking of trying with Rust looks like it will be predominantly Unsafe Rust - using a lot of structures that are multiply referenced by necessity (or not?). I'm doing a lot of reading and thinking prior to starting because I really want the benefit from Rust as well as changing my thinking if there are good changes to be made there. Using an array of items and having them reference each other by index should satisfy the Rust compiler, but that doesn't actually solve the potential problems of trying to traverse (update) a complex data structure with parallel threads. The challenge of doing this suggests to me that the claims are overblown. A modestly complex data structure seems to require disabling all that safety but I am still learning and contemplating different approaches. Questioning basic assumptions seems prudent. I want to believe, but at this point I'm not convinced.
- bad_user 8y ago> difficult -to-impossible to misuse in such a way as to cause a deadlock or race condition Rust doesn't solve deadlocks or race conditions. Rust only makes it hard to accidentally share a memory location, but that's only a very small part of the problem, race conditions being a fundamental part of computer science, being baked into any language that supports expressing and joining asynchronous processes. I would be generous in agreeing with a statement about Rust making it a little more difficult to end up with a deadlock or unwanted race condition, except that's not true when compared with many other high level languages. Also nothing is impossible until you prove it via formal methods (e.g. TLA+).
- lmm 8y ago> Rust only makes it hard to accidentally share a memory location, Not just a memory location, any value. You can use the tools Rust gives you on any piece of state you care to manage - a database connection, a remote server, the office coffee machine - represent it as a value and Rust will let you check that it's owned where you want it to be owned, borrowed where you want it to be borrowed and so on. > Also nothing is impossible until you prove it via formal methods (e.g. TLA+). What's the distinction you're drawing between something like TLA+ and something like the Rust borrow checker?
- pcwalton 8y ago> I would be generous in agreeing with a statement about Rust making it a little more difficult to end up with a deadlock or unwanted race condition, except that's not true when compared with many other high level languages. It is easy to specifically describe what Rust prevents: unsynchronized memory access from multiple threads. What other high-level languages allow read-write shared-memory multithreading and guarantee that? > Also nothing is impossible until you prove it via formal methods (e.g. TLA+). The fact that unsynchronized memory access is impossible in safe Rust (modulo compiler bugs, CPU bugs, etc.) is something that nobody seriously doubts. It's obvious. I'm glad people are working on proving it, but the proof is an academic exercise.
- Svenskunganka 8y ago> It is easy to specifically describe what Rust prevents: unsynchronized memory access from multiple threads. What other high-level languages allow read-write shared-memory multithreading and guarantee that? Pony maybe? https://www.ponylang.org/discover/#what-is-pony https://www.ponylang.org/discover/#what-is-pony At least that's my impression of its reference capabilities.