this post was submitted on 13 Mar 2024
38 points (97.5% liked)

Rust

5989 readers
17 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 1 year ago
MODERATORS
 

A saw this on Mastodon, and found it interesting. Rust already prevents a lot of race conditions, but deadlocks when using a mutex is still possible (and I have actually had one myself, though I caught it during testing). So, it would be nice if it would be possible to catch these cases at compile time. Now, seems to be just a proof of concept, but it is always nice to see the direction people are going and what areas are explored.

you are viewing a single comment's thread
view the rest of the comments
[–] blackjacksepp@feddit.de 3 points 8 months ago (2 children)

I never used C++'s scoped locks but as far as I can tell they perform runtime deadlock detection while this crate is compile-time only with near to none code produced in the resulting binary.

This is done by enforcing to either lock every Mutex the thread needs at once or none at all. Thread keys are used to represent this with the type system.

[–] naonintendois@programming.dev 5 points 8 months ago

I don't see how that can be used to make performant code though. I usually want to make my locked regions as small as possible to avoid how long other threads are blocked for.

[–] Miaou@jlai.lu 2 points 8 months ago* (last edited 8 months ago)

So this is solving the problem of reentrant deadlocks, with a non compile-time enforceable exclusion mechanism in the form of a threadkey.

It's quite different from solving deadlocks in general, and mostly moves the problem to getting the thread key. It's an interesting thought experiment, but unless I'm missing something else, it has no practical purpose over a try_lock.

But anyway, thanks for taking the time to explain, I should have read more carefully