News for hackers. Stuff that matters.
Re:Rust Is Hard, Or: The Misery of Mainstream Programming by bombela on Thursday June 02, 2022 @09:51PM (#31603273)
Rust doesn't protect you against deadlock.

I wonder if it is similar to the halting problem. Can deadlocks even be prevented in theory?

Re:Rust Is Hard, Or: The Misery of Mainstream Programming by mjn on Thursday June 02, 2022 @10:43PM (#31603631)
In the general case you're right, it's equivalent to the halting problem. The outline of the proof by reduction: set up two communicating processes in a way that will deadlock iff a particular loop in one process fails to terminate. So if you had a deadlock detector for arbitrary communicating processes, you could use turn it into a termination detector for arbitrary loops.
Re:Rust Is Hard, Or: The Misery of Mainstream Programming by jandrewrogers on Friday June 03, 2022 @12:30AM (#31604309)
Yes, deadlock-free lock systems are an ordinary part of OLTP database engines. They don't prevent deadlocks per se so much as detect them and dynamically resolve them.

The mechanism is costly but elegant. If a lock you are trying to acquire is owned by another thread, you inspect the locks you own to determine if that thread is waiting on one of your locks. When a deadlock is detected, there are several strategies to automatically resolve it e.g. rolling back one of the threads to a point where forward progress can be safely serialized.

No one wants to use these mechanics for ordinary code, due to their cost. For the fashionable thread-per-core software architectures, deadlocks aren't something you commonly have to worry about.

Re:Rust Is Hard, Or: The Misery of Mainstream Programming by Waterluvian on Thursday June 02, 2022 @10:31PM (#31603547)
Only if the priority is flat and not some sort of graph, is my guess.