Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

threads?/

 
srikanth reddy
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

fnds
here the output is 012012....instead of 012345 ..
i know that if the variable is declared as volatile then every thread uses a copy of it and so the variable cant be declared both volatile and final ...here it is not volatile then how come they uses their own copy..
but here ..if we wud have used static then there is only one variable and can expect 012345
 
Vlado Zajac
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


2 different objects of Question47
2 different objects of A (Question47.a)
2 different variables i

If Question47.a was static, the output would be 012345.
 
Vlado Zajac
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Volatile does not mean that every thread has a copy (that does ThreadLocal).
Volatile means that threads cannot make temporary copies of the variable (which may otherwise be used for optimization).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic