bob wrote:

> 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;
>
That would definitely work. Whether it's necessary depends on whether the 
analysis 
I outlined upthread is correct.

The initialization to 'false' is redundant, FWIW. The declaration as shown 
in the 
example and here assigns 'false' to 'mRun' twice. However, the 
initialization pays 
this small penalty for good reason - it emphasizes that the logic of the 
variable 
depends on its initial state being 'false', and thus adds to the 
self-documentation 
of the code.

As a matter of style, I would place the 'private' keyword first: 

  private volatile boolean ...

This is consistent with the conventional 'private static final boolean', 
'private final boolean', and the like.
 

> 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.
>>
>
-- 
Lew
 

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to