-
Notifications
You must be signed in to change notification settings - Fork 371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add shims for RwLock::try_read/RwLock::try_write #1157
Conversation
This was already attempted in #905, and the same concerns as there apply: I don't think it is a good idea to land this as is. (Also, you are swamping us with the sheer amount of PRs. Your contributions are appreciated, but it might take |
That said, once I am through that backlog, I'd be happy to mentor you for fixing #781 if you are interested :) |
Sure, totally understood. I will read over those and work on re-implementing these shims. |
I think I need some pointers on working with memory in Miri to get this implemented properly. Mutex/lock behavior when locked twice from the same thread depends on the attributes/kind of the synchronization primitive, so we need to know the kind of the mutex. The hard part is that this has to interoperate with I tried using What would be the best way to read and write fields in these quasi-opaque FFI structs? The two vague ideas I have at this point are using |
I imagined we'd just ignore that and always treat reentrant locking as an error.
I am not entirely sure what it is that you did, but the error probably arises because you used But also, your description is so high-level that I have little clue what concretely it is you are trying to do, so I can't really make any suggestions for how to do it. |
I got it working on Linux, but I need to revisit my memory layout on macOS, because mutex and rwlock objects have a 32-byte signature at the beginning of their static initializer. Edit: fixed! |
418e5d3
to
d9c2a9b
Compare
Before reviewing this huge PR, it'd help if you could answer my questions above -- I don't see yet why we should even care about how exactly these platforms represent what. Why can't we just make all locks error on reentrancy? |
The standard library uses both |
FWIW I'd be perfectly fine to make But now you already put in all the work. ;) It might just take a bit until I get around to a review, there are at least 3 other PRs before it in my queue. |
I just added a separate test that exercises |
Nice catch! I didn't even know that relied in reentrant mutexes. It would also be good to have a test that exercises the locking API more directly, as we have little control over how e.g. |
Okay, I added a test for that. I had to do it via libc, because |
☔ The latest upstream changes (presumably #1167) made this pull request unmergeable. Please resolve the merge conflicts. |
52cb7f4
to
89ca0d1
Compare
Let's see how these new tests do on Windows... @bors try |
tests/run-pass/libc.rs
Outdated
assert_eq!(libc::pthread_rwlock_destroy(rw.get()), 0); | ||
} | ||
} | ||
|
||
fn main() { | ||
#[cfg(not(target_os = "macos"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it would make sense to switch this to cfg(target_os = "linux")
as well? Would be good to be consistent within the file here.
Aside from that last nit, this is ready to go. :) |
Nit addressed! |
Thanks a lot, this is such a great new feature. :) |
📌 Commit 80497e5 has been approved by |
☀️ Test successful - checks-travis, status-appveyor |
This implements proper locking so that we can check for reentrancy and implement the
try_*
methods.Fixes #781