Use TypeState to prevent Deadlocks?

2-3 years ago there was a conference talk, which I recall as wrapping Locks in a type ladder. So the compiler ensures that everyone can only obtain them in the same order. Happy enough that this was now common know-how, I did not bookmark it. And now I can’t find it anymore. Do you have the link?

In fact I find very few crates related to deadlocks, and little else. There is a 6 years old Compile time lock ordering approach to deadlocks with an interesting but rather verbose solution. That got almost no reaction.

About fuchsia netstack3

4 Likes

I was in the audience for the talk and was quite entertained by it. I'll be curious if the approach there works well for you.

1 Like

In the job I was working at the time, I didn't end up enforcing the ordering via the type system for various reasons, but there's useful info in the approach, I think. habitat/dev-docs/dev/design_documents/locking.md at main · habitat-sh/habitat · GitHub is a good place to start.

This solution has me in awe of what Rust can do! I’ve packed all the initial lock wrapping into a macro Simple API · Issue #2 · howtocodeit/lock_tree · GitHub because there was too much boilerplate around it lock_tree

Does this feel Rusty enough? What would you change?