-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Possible races #8922
Possible races #8922
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know much about multithreading unfortunately. And sorry for reviewing so late.
- What does "HB's transitivity" mean? At least I could find out that CoW means "copy-on-write".
- I also don't understand what
volatile
does exactly: I have read this article but I don't understand how it applies here and why you need it. Do you use it to make sure all class instance fields are up-to-date whenever you read any volatile field from them? - What is the difference between having
synchronized
in a method signature vssynchronized(this)
just inside? - Is the queue actually ever accessed from multiple threads? The player service and the UI both run on the main thread afaik. If I am wrong on this then, well, be sure to tell me ;-)
- Did you test these changes thoroughly?
no, unfortunately, I did not test what I wrote, but I can say one thing for sure: The point is that the state between threads is dragged through the release/acqure state; volatile is stronger than this semantics (provides an order guarantee) If you look into the implementation of the Atomic classes, you will see that reading and writing (get/set) happens to a volatile field or VarHandle.setVolatile/getVolatile There is another situation when you are guaranteed to write and read only in one thread, then you don’t need any synchronization / atomic (volatile) at all you can read more details here: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation, now I've understood a little bit more!
Checkstyle is failing because the code is not following our style.
At the moment I am not able to test whether the queue works correctly because it is bugged on dev
...
app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueue.java
Outdated
Show resolved
Hide resolved
app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueue.java
Outdated
Show resolved
Hide resolved
|
I don't understand why the |
What is it?
Description of the changes in your PR
Let's start in order:
First, if you write under a lock, it doesn't mean that reading a non-thread-safe collection is thread-safe, you break HB's transitivity:
There are two ways out in this situation:
But, there are still problems, the fact is that the class is non-thread-safe by design:
P.S eeven though the race may be out of scope for your implementation, if you are already making the methods thread-safe, you need to make those method binders thread-safe
Unfortunately, this is the first class in which I encountered a race, such a problem may be in other classes
Fixes the following issue(s)
Possible races in perspective