-
Notifications
You must be signed in to change notification settings - Fork 129
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
Assertion failed #35
Comments
To reproduce:
If I dump indexes after each operation this way
It is clear this is caused by the diverged non-atomic caches and the real values:
If ensure the equality between the caches and the indexes in the end of the
|
@galchinsky On which CPU are you running? For example, Apple Silicon CPU behaves a bit differently than Intel, as I could experiment (SPSCQueue was not involved). |
@Philippe91 it's a simple single-threaded example with a few push and a few pop operations, I don't think CPU can make a difference here. |
If an item is popped without ever having been accessed via front(), front() may subsequently return non-null even though the queue is empty.
I submitted a PR to fix this, see PR "Bug fix for #35". |
This solves the problem, apparently. This being said, the logic behind the cached indexes system introduced by @rigtorp is challenging to grasp in my mind. I am considering reverting to the implementation prior 3a0507a. |
I just moved to Facebook's queue, because who knows are there any other bugs like that |
I have the same problem.
Output: If add |
And function
If you run the |
It's just an assertion fail in the class destructor because Because you weren't supposed to call |
There seems to be a misunderstanding of the pre-conditions of calling This is a concurrent queue intended to be used by two threads. In that case the only way for the reader thread to know if there is more data to read is by calling This code invokes undefined behavior (and triggers the assert):
This code correctly checks that the queue is not empty:
Since you are not reading |
I don't remember the details (even where the assertion got triggered), but here are 3 chunks of code I had before moving to the facebook's queue, and checking for front after checking for emptiness or size doesn't seem obvious to me.
another one
and
Apparently, given there are debug outputs, it was the last one that triggered the assertion.
|
Yes, those first two are invalid and will break the queue invariants.
I really should never have used the front() and pop() APi from std::queue.
Instead they should be a single transaction try_pop() that can return a
value. Or a zero-copy version that visits the value in-place using a lambda.
…On Mon, Sep 25, 2023 at 5:43 AM Dmitry Galchinsky ***@***.***> wrote:
I don't remember the details (even where the assertion got triggered), but
here are 3 chunks of code I had before moving to the facebook's queue, and
checking for front after checking for emptiness or size doesn't seem
obvious to me.
while (!queue.empty()) {
lapper.put_sample(*queue.front());
queue.pop();
}
another one
while (queue.size() > 4) {
queue.pop();
}
and
while (queue.front()) {
DBOUT("$" << queue.writeIdx_ << " " << queue.writeIdxCache_ << " " << queue.readIdx_ << " " << queue.readIdxCache_);
queue.pop();
}
Apparently, given there are debug outputs, it was the last one that
triggered the assertion.
Pushing was being done this way, in a separate thread:
bool success = queue.try_push(workbuf);
if (success) {
last_timestamp = buf.timestamp;
}
—
Reply to this email directly, view it on GitHub
<#35 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABLO26TGO4YASZ6VM3UXY3X4FN55ANCNFSM5SFF52EQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Hi!
I've been using SPSCQueue for some time and just updated to the latest version and now hit this:
Any advice? Thank you!
The text was updated successfully, but these errors were encountered: