• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Volatile Question

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are array members treated with volatile style semantics?
Java does not have a way to declare array members as volatile so is the compiler allowed to make a working copy of an array member? (JLS seems to say yes.) And if so, does the copy have to be reconciled on every reference as a volatile variable does? (JLS seems to say no.)
In the code below, an array member is changed by another thread. Is that change visible in the main thread?

From my reading of the JLS I believe that the only way to ensure that working copies of array members are reconciled is to use locking. This would mean that my example is incorrectly coded and would (probably) loop forever.
I understand how to fix the example but I would like to find out if I am understanding what the JLS is telling me. Any comments?
 
reply
    Bookmark Topic Watch Topic
  • New Topic