It is possible that the mRun variable ought to be declared as "volatile".
/** Indicate whether the surface has been created & is ready to
draw */
*volatile* private boolean mRun = false;
On Sunday, September 16, 2012 11:36:09 AM UTC-5, sdb wrote:
>
> I'm new to android development and have been studying the Lunar Lander
> example included in the SDK to get a better understanding of how the
> SurfaceView works. I noticed that the mRun member of the LunarThread class
> is updated by the setRunnable() method of the LunarThread class which is
> called from the LunarView class within the surfaceCreated() and
> surfaceDestroyed() methods.
>
> It seems to me that mRun is being updated by the main thread for the
> SurfaceView, but is being repeatedly read in a tight loop in LunarThread.
> My question is: is this use of mRun thread safe and if so, why/how?
>
> I'm not sure, but maybe it is thread safe because mRun is a simple boolean
> variable and is only updated from one of the two threads involved. If mRun
> was a more complext object and/or it was being updated by different by both
> threads,then perhaps this example would not be thread safe without the use
> of some form of synchronization mechanism.
>
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en