Skip to content
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

Use explicit wrapping_add … #43588

Merged
merged 1 commit into from
Aug 9, 2017
Merged

Use explicit wrapping_add … #43588

merged 1 commit into from
Aug 9, 2017

Conversation

dns2utf8
Copy link
Contributor

@dns2utf8 dns2utf8 commented Aug 1, 2017

… to prevent potential unexpected behavior on debug builds.

@rust-highfive
Copy link
Collaborator

r? @sfackler

(rust_highfive has picked a reviewer for you, use r? to override)

@@ -141,7 +141,7 @@ impl Barrier {
pub fn wait(&self) -> BarrierWaitResult {
let mut lock = self.lock.lock().unwrap();
let local_gen = lock.generation_id;
lock.count += 1;
lock.count.wrapping_add(1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need lock.count = lock.count.wrapping_add(1) (wrapping_add returns the new value instead of modifying in-place).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can this ever overflow? Wouldn't that require more than usize::MAX_VALUE threads?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are both right. This can not overflow and the syntax was wrong. Thank you

@aidanhs aidanhs added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Aug 3, 2017
@arielb1
Copy link
Contributor

arielb1 commented Aug 8, 2017

Hi @dns2utf8. This PR needs fixing - are you still working on it? Just a friendly ping to keep this on your radar.

Also, could you provide an example in which an overflow can happen, to make sure it is handled correctly?

@dns2utf8
Copy link
Contributor Author

dns2utf8 commented Aug 8, 2017

Thank you for the ping.

The example I would like to prevent is when reusing a barrier the generation could trigger an overflow panic at some point.

@sfackler
Copy link
Member

sfackler commented Aug 9, 2017

@bors r+

@bors
Copy link
Contributor

bors commented Aug 9, 2017

📌 Commit 702750c has been approved by sfackler

@bors
Copy link
Contributor

bors commented Aug 9, 2017

⌛ Testing commit 702750c with merge 75617d7c06406ef8db44f6f12d4cb8eaabbe4130...

@bors
Copy link
Contributor

bors commented Aug 9, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: sfackler
Pushing 75617d7c06406ef8db44f6f12d4cb8eaabbe4130 to master...

@bors
Copy link
Contributor

bors commented Aug 9, 2017

👀 Test was successful, but fast-forwarding failed: 422 Update is not a fast forward

@kennytm
Copy link
Member

kennytm commented Aug 9, 2017

@bors retry #43535

@bors
Copy link
Contributor

bors commented Aug 9, 2017

⌛ Testing commit 702750c with merge c2de81f...

bors added a commit that referenced this pull request Aug 9, 2017
Use explicit wrapping_add …

… to prevent potential unexpected behavior on debug builds.
@bors
Copy link
Contributor

bors commented Aug 9, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: sfackler
Pushing c2de81f to master...

@bors bors merged commit 702750c into rust-lang:master Aug 9, 2017
@dns2utf8 dns2utf8 deleted the wrapping_add branch August 9, 2017 16:02
@dns2utf8
Copy link
Contributor Author

dns2utf8 commented Aug 9, 2017

Cool! Thank you 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants