-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add a comment to Arc::MAX_REFCOUNT
#37605
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
Conversation
r? @brson (rust_highfive has picked a reviewer for you, use r? to override) |
You don't need to keep them all in memory, they can be fed into |
bbcc0eb
to
d2d6658
Compare
I see you're right. The following code runs in 10 seconds on my laptop:
So for 32 bit systems, testing this would be feasible. Should I add a test which only runs on 32 bit systems? |
Thanks for the PR! I'm not sure I quite understand the change, though, or why it's necessary. The reference count can get much higher than The "problem" comes about when the refcount hits |
@alexcrichton The reference count can't indeed get much higher thatn Currently it is possible to exceed the maximum refcount (as defined by the constant). This should not be possible (?). If this was meant to be just a soft limit, this PR is probably meaningless. |
Yeah this may just be a badly named constant. There's no actual need to prevent the refcount from going above this constant, it's just an indicator that calls to |
I think it's in order to do some kind of annotation in the code to inform the reader about this. Right now it kinda looks like the programmer has made an off-by-one typo in line 463. I could (instead of the proposed change) add a comment at the declaration of |
Yeah so to be clear the code as written I believe is working as intended, so there's no burning need to change it. Both before and after this patch are functionally ok, but the patch itself isn't required. I'd be fine with renaming the variable perhaps though or adding a comment. |
d2d6658
to
4f7fba2
Compare
The constant name `MAX_REFCOUNT` suggests that the value is a _hard_ limit on the amount of references to an `Arc`. This is a more soft limit however. This commit adds a comment to the constant to annotate this. See also: PR rust-lang#37605
4f7fba2
to
99aaccd
Compare
I undid the original changes and added a comment to |
@bors: r+ rollup |
📌 Commit 99aaccd has been approved by |
Would it be possible to update the PR title and description to match what the PR now does? Since both are copied into commit history by bors/homu, it would be nice to have them up-to-date. Not critical though, so just a suggestion. |
⌛ Testing commit 99aaccd with merge 045a727... |
Fix Arc::clone()'s MAX_REFCOUNT check (off-by-one) Before, the strong count of an `Arc` could be set to `MAX_REFCOUNT + 1`, because when this happened, `old_size` would be exactly `MAX_REFCOUNT`. `Arc::clone()` would not abort. This commit changes the check in `Arc::clone()` to also abort if the old value is equal to `MAX_REFCOUNT`, because then the new value will be equal to `MAX_REFCOUNT + 1`. A test would require allocating memory for `isize::MAX` pointers. This would probably crash any machine, so no test is submitted with this commit.
The constant name `MAX_REFCOUNT` suggests that the value is a _hard_ limit on the amount of references to an `Arc`. This is a more soft limit however. This commit adds a comment to the constant to annotate this. See also: PR rust-lang#37605
Arc::MAX_REFCOUNT
Before, the strong count of an
Arc
could be set toMAX_REFCOUNT + 1
, because when this happened,old_size
wouldbe exactly
MAX_REFCOUNT
.Arc::clone()
would not abort.This commit changes the check in
Arc::clone()
to also abort ifthe old value is equal to
MAX_REFCOUNT
, because then the newvalue will be equal to
MAX_REFCOUNT + 1
.A test would require allocating memory for
isize::MAX
pointers.This would probably crash any machine, so no test is submitted
with this commit.