Earlier quoted context omitted.
In the example it seems pretty clear to me that: Mutex::new(AppConfig::default()); ...is meant to be acquiring a mutex protecting some global config object, yes? That's what I'm calling a "global lock". > There’s no priority inversion possible because locks can only ever be held in decreasing orders of priority T1 T2 -- -- small_lock(); big_lock(); small_lock(); ...and now any other thread that needs big_lock() spins…
Mutex::new creates a lock, it doesn’t acquire one. Look at the API - if big_lock and small_lock are at the same level, you would need to acquire the lock simultaneously for both locks which is accomplished within the library by sorting* the locks and then acquiring. If you fail to acquire small_lock, big lock isn’t held (it’s an all or nothing situation). This exact scenario is explained in the link by the way. You c…
Surelock: Deadlock-Free Mutexes for Rust
51–60 of 90 posts
Re: Surelock: Deadlock-Free Mutexes for Rust
#52I agree with the author: it's a shame that TVars aren't catching on in more languages. They are a great idea from the database world, that we could use in the rest of computing, too.
Re: Surelock: Deadlock-Free Mutexes for Rust
#53Earlier quoted context omitted.
The canonical industrial explanation “why not” is probably this 2010 piece from Joe Duffy @ Microsoft: http://joeduffyblog.com/2010/01/03/a-brief-retrospective-on-...
I don’t think we read the same thing. > Models can be pulled along other axes, however, such as whether memory locations must be tagged in order to be used in a transaction or not, etc. Haskell requires this tagging (via TVars) so that side-effects are evident in the type system as with any other kind of monad. We quickly settled on unbounded transactions. Snip > In hindsight, this was a critical decision that had fa…
Re: Surelock: Deadlock-Free Mutexes for Rust
#54Earlier quoted context omitted.
Mutex::new creates a lock, it doesn’t acquire one. Look at the API - if big_lock and small_lock are at the same level, you would need to acquire the lock simultaneously for both locks which is accomplished within the library by sorting* the locks and then acquiring. If you fail to acquire small_lock, big lock isn’t held (it’s an all or nothing situation). This exact scenario is explained in the link by the way. You c…
No, the entire point of what I was saying is that big_lock and little_lock are at two different levels.
T2 might “spin” waiting for small lock but assuming small lock is released at some point you’ve not got a deadlock (and by construction it’s impossible for small lock to have it’s release blocked on the acquisition of a lock that depends on big_lock).
That’s the whole point of having a level to the locks and to the key that you have to give up to acquire that lock.
Your terminology is also off. Mutexes are not implemented through spin locks. It’s an atomic operation and when lock acquisition fails you call futex_lock (or whatever your OS api is) to have the thread be put to sleep until the lock is acquired.
Re: Surelock: Deadlock-Free Mutexes for Rust
#55I can't understand why address instability is a problem: if a Mutex is moved, then it can't be locked (because you need to hold a borrow while locked, which impedes moving), so using addresses is perfectly fine and there is absolutely no need to use IDs. Also the fact that it doesn't detect locking the same mutex twice makes no sense: a static order obviously detects that and when locking multiple mutexes at the same…
Don't address introduce ambiguous locking order across attempts? While not obviously problematic, that seems weird enough you would need to validate that it is explicitly safe.
Re: Surelock: Deadlock-Free Mutexes for Rust
#56Earlier quoted context omitted.
Lock ordering is indeed a common pattern to avoid deadlocks. I learned it in school in the 80's and MIT teaches it today. [0] [0] https://web.mit.edu/6.005/www/fa15/classes/23-locks/#deadloc...
I'm aware. I'd be curious to hear the authors reason to not prefer a LockSet everywhere.
Opting out of lock levels was a design goal. By default all locks are are Level1, so the level can be omitted thanks to the default type parameter filling it in for you. Levels have no runtime cost, so sidestepping them is free. This lets you live in an atomic-locks only world if you want, and if you later find that you need incremental locks, you can add more levels at that time :)
[EDIT: fixing autocorrect typos when I got back to my laptop]
Re: Surelock: Deadlock-Free Mutexes for Rust
#57[flagged]
Author here! This post was human written, LLM proofread, and edited a couple times as folks pointed out broken links and minor errors when it was posted to r/rust a few days ago. As someone mentioned lower in the thread, there's a form of what is sometimes called Bay Area Standard that both very online humans and LLMs have absorbed. I find it FASCINATING that we're in an era where we have to prove our humanity, and t…
It's things like "perfectly invisible in code review, happy to pass CI a thousand times, then lock your system up at 3am under a request pattern that no one anticipated." which are a dead tell it was written by ChatGPT
I'll bet you 2 beers the LLM you used to proofread the post was indeed ChatGPT.
Re: Surelock: Deadlock-Free Mutexes for Rust
#58Earlier quoted context omitted.
No, the entire point of what I was saying is that big_lock and little_lock are at two different levels.
If big lock and little lock are at different levels you won’t have a key at the appropriate level to create an inversion by trying to acquire in the first place. T2 might “spin” waiting for small lock but assuming small lock is released at some point you’ve not got a deadlock (and by construction it’s impossible for small lock to have it’s release blocked on the acquisition of a lock that depends on big_lock). That’s…
Re: Surelock: Deadlock-Free Mutexes for Rust
#59Earlier quoted context omitted.
I don’t think we read the same thing. > Models can be pulled along other axes, however, such as whether memory locations must be tagged in order to be used in a transaction or not, etc. Haskell requires this tagging (via TVars) so that side-effects are evident in the type system as with any other kind of monad. We quickly settled on unbounded transactions. Snip > In hindsight, this was a critical decision that had fa…
Having worked a bit on a hobby STM in C++ (spun out of a DB startup) I would have to agree. Fully transparent STM that depends on a "sufficiently smart compiler" for an imperative language with unrestricted side effects is hopeless. But I do think that a much humbler version of STM is feasible for C++ or Rust, requiring much more explicit cooperation from the programmer. I haven't worked on this for 3 years but hope…