You need some sort of synchronization mechanism if you want to ASSURE
that the second thread sees the first thread's change of the flag
IMMEDIATELY.  Otherwise the value of the flag could be cached (to a
degree), even though declared "volatile".  (However, one rarely runs
into a situation where twiddling a single flag isn't "safe" without
syncing.)


On Oct 18, 4:21 am, xeagle <xeagle...@gmail.com> wrote:
> Hi,
>
> I use a boolean variable "flag" both in main and child thread. This
> "flag" is used to notify child thread to exit. I only use simple
> operation, e.g., "flag=false", "if (flag) {}". As I know, in java,
> "get and set a boolean variable" is atomic. So "synchronized" is not
> needed for variable "flag", declaring "flag" as "volatile" is enough.
>
> Is this still true in Android?
>
> Thanks
> Jason He

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