-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
RwLock::{try_read, try_write}
(#72)
This is a little tricky because `std` is unclear about whether a thread can acquire the same read lock multiple times. For `read` it says: > This function might panic when called if the lock is already held by > the current thread. So acquiring a second read lock _might_ fail. But for `try_read` it says: > This function will return the WouldBlock error if the RwLock could not > be acquired because it was already locked exclusively. suggesting that `try_read` _must_ succeed the second time (the lock is not held exclusively). We resolve this ambiguity by choosing a conservative semantics that always forbids a thread acquiring the read lock twice. This helps us catch deadlocks, especially in async programs where a task might nondeterministically migrate between threads and only deadlock if that migration didn't happen. Another difficulty with this change is that causality is pretty hairy for the read side of a `RwLock`. In principle, concurrent readers shouldn't inherit each other's causality, as they don't affect whether the lock was readable or not. But that's really hard to implement, especially with `try_write` in the picture too. So again we choose a conservative implementation for our vector clocks that just always inherits causality from all prior lock holders. This is likely too strong, so we'd explore unnecessary symmetries, but I can't convince myself of the correctness of a weaker implementation.
- Loading branch information
1 parent
8bd99ef
commit 3a007d6
Showing
5 changed files
with
525 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.