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

Not considering minTime < oldTime condition if compare_exchange_weak fails #7

Closed
benstadin opened this issue Dec 2, 2022 · 1 comment

Comments

@benstadin
Copy link

benstadin commented Dec 2, 2022

Before entering the loop the condition is handled for the case when the previous run (oldTime) is older than the earliest possible bucked (minTime) of the buffer window.

However, for the case that compare_exchange_weak fails and newTime is reset to oldTime back again and the loop is re-run, setting it to old time is wrong as it does ignore that case?

    if (minTime > oldTime) {
      newTime = minTime; // <--- newTime changed
    }

    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; // <-- newTime reset to oldTime, not considering the eventually required shift to minTime
    }
@rigtorp
Copy link
Owner

rigtorp commented Mar 29, 2023

Yes, you're right. Take a look at the latest version in master, it fixes this problem!

@rigtorp rigtorp closed this as completed Mar 29, 2023
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

2 participants