-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Question: Is 'volatile' redundant in RecordFBOActivity.RenderThread.mHandler field? #68
Comments
I think your reasoning is correct -- A check for null is strictly necessary in at least the View UI callbacks, since in theory somebody could click on a UI element before the surface creation completes (which requires a round-trip to SurfaceFlinger by way of the window manager). However, the existing check is incorrect: the check for null should be on If you look at TextureFromCameraActivity, which was written later, functions like My guess is that the volatile declaration and null checks are left over from a previous iteration of the code (not checked in) that didn't have |
I see, that makes sense. I did thought that changes left from previous code versions could probably be the case, I just wanted to verify my understanding. I am investigating the idea of creating a version of the Regarding the co-existence of activity and surface life cycles I can only imagine. I have some experience myself from an Android game I have worked on. Even though I have used Anyway, thanks for answering my question and again for the great work. |
Hi,
First of all I have to say that grafika really helped me improving my understanding on how OpenGLES and android work together, so thanks for all the great work!
In my question: I 've been been playing recently with
RecordFBOActivity
class, and I 've noticed that in the render thread theRenderThread.mHandler
field is declaredvolatile
due to thread visibility concerns (expressed in the comment below):I believe however that the
volatile
declaration is redundant because of the way the two threads work together during the render thread initialization. More specifically:RecordFBOActivity.surfaceCreated()
the UI thread creates the render thread, starts it and waits until the render thread is ready:RenderThread.run()
themHandler
is assigned and then synchronizes on the samemStartLock
lock the UI thread is waiting for.I would expect that when the UI thread resumes after
waitUntilReady()
the visibility of themHandler
field is guaranteed (the assignment should be visible due to happens-before relationship), so we do not need thevolatile
declaration. As far as the UI thread is concerned it should never be able to see anull
value for themHandler
field (the field is not re-assigned anywhere else).If the above is true, then all calls in the UI thread that check if
getHandler()
returns anull
value, are redundant too and could be removed simplifying the code a little bit.Is the above understanding correct or am I missing something here?
Thanks in advance
The text was updated successfully, but these errors were encountered: