-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Weird behaviour of switch when the outer sequence completes but the last inner still has elements #737
Comments
Confirm this is a bug in |
I see another issue. The op uses
|
|
Sorry, @akarnokd , you're right. The initial step is not thread-safe. |
If latest is not volatile, latest can not be guaranteed to be 0. |
I was wrong, didn't "see" the synchronized. Btw, instance initialization esures that the While you are at it, could you move any |
Just refreshed my java concurrency knowledge. |
When you call |
From JSR-133 3.5 Final Fields, "a thread that can only see a reference to an object after that object has been completely initialized is guaranteed to see the correctly initialized values for that object’s the constructor is only guaranteed to make |
However, I don't know if the default value 0 of a non-final field will be guaranteed to be visible to other threads after the constructor is finished. Is it possible that other threads see a random uninitialized value? |
If publication is not safe, then there is no happens-before relationship between the assignment of the instance's fields and its unsafe publication. If the instance contains final fields, then Java inserts a memory barrier at the end of the constructor and publication is ensured to be safe |
From JLS 17.4.4. Synchronization Order,
So if a field is the default value (zero, false, or null) and does not be assigned, the default value is always visible to every thread. |
The buffer operator has been rewritten with extra effort for making sure values don't fall between two windows if timespan == timeshift. Does it work for you? |
Closing as no further comments in a long time. This is likely fixed with the recent fixes to @dvtomas Please re-open if there are still issues. |
Hi all,
I just ran into a behavior of switch (as of RxJava 0.16.0) that I don't think is correct. When the outer sequence completes, but the last inner sequence that the operator was subscribed to still has some elements, I'd expect the operator to either
However, the output of the code below makes me think that neither is the case with the current implementation. When I try to run
it prints (at least for me)
List(a 0, a 1, b 0, b 1, b 2, b 3, b 4, b 5, b 6)
That seems correct for the a's - two of them fit into the 500 milli window, but why there were 6 b's emitted I don't understand, and it seems to me as quite an arbitrary number.
Thank you for any insights.
Best regards,
Tomáš Dvořák
The text was updated successfully, but these errors were encountered: