-
Notifications
You must be signed in to change notification settings - Fork 32
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
feat: add forget
method to semaphore guards
#73
Conversation
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.
What advantage does this have over just calling mem::forget
on the locks?
If we don't provide an explicit |
In fact, I think the |
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.
I get the idea, although it seems somewhat useless without a manual unlock method. Although we can save that for a future PR.
src/semaphore.rs
Outdated
|
||
// Drop the inner `Arc` in order to decrement the reference count. | ||
// SAFETY: `manual` not used after this | ||
let _arc = unsafe { addr_of_mut!(manual.0).read() }; |
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.
I'd rather avoid the unsafe
here. I would prefer to make the type a wrapper around Option<Arc<...>>
, and then make this just take
the Arc
out without any of the other dropping.
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.
Arc
has only one niche currently, it would be a shame to use it up.- There is already another
unsafe
block in this library that performs the same operation. (Hopefully, my RFC 3466 will be accepted someday and then neither of these will be necessary…)
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.
For both cases, I value safety over precedent here. smol-rs
doesn't have the resources to conduct thorough unsafe
audits (outside of off-the-shelf tools like Miri), so the less unsafe code we have the better.
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.
For both cases
What do you mean by "both cases" here? Are you saying I should remove the unsafe
in the RwLock
impl also? (The performance cost would be much greater over there compared to here.)
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.
Not in this PR, but I am skeptical of premature optimizations like this.
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.
I've removed the unsafe
.
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.
(The performance cost would be much greater over there compared to here.)
Specifically, it would mean a branch on every access to the value behind the lock guard.
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.
We can benchmark this in the future
addb676
to
a3856b1
Compare
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.
Thanks!
No description provided.