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

newTime updated multiple times? #3

Closed
dnj12345 opened this issue Oct 30, 2017 · 1 comment
Closed

newTime updated multiple times? #3

dnj12345 opened this issue Oct 30, 2017 · 1 comment

Comments

@dnj12345
Copy link

dnj12345 commented Oct 30, 2017

Not sure if it's an issue or not, but definitely a question... :)

If the 'compare_exchange_weak' call in the code below fails, the newTime would be incremented by timeNeeded multiple times. Is that the intent?

    for (;;) {
      newTime += timeNeeded;
      if (newTime > now) {
        return false;
      }
      if (time_.compare_exchange_weak(oldTime, newTime,
                                      std::memory_order_relaxed,
                                      std::memory_order_relaxed)) {
        return true;
      }
      newTime = oldTime;
    }
@dnj12345
Copy link
Author

Never mind, understood. oldTime is copied to the newTime on the last line of the loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant