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

In the LF_Queue, the getWriteIndex() might not be thread safe #4

Open
sowgali opened this issue Jan 24, 2024 · 0 comments
Open

In the LF_Queue, the getWriteIndex() might not be thread safe #4

sowgali opened this issue Jan 24, 2024 · 0 comments

Comments

@sowgali
Copy link

sowgali commented Jan 24, 2024

In lf_queueu.h, the following function might not be thread-safe because the updateWriteIdx() is called after calling getNextToWriteTo()

auto getNextToWriteTo() noexcept {
      return &store_[next_write_index_];
}

This might lead to two threads accessing the same write location. The same thing applies to reads as well. Let me know if there is anything wrong with my understanding. Should we use a CAS-based lock-free queue, however, it will have to spin. Or we should atomically increment the next_write_index_ with modulus.

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

No branches or pull requests

1 participant