What requirements apply to volatile variables



  • At the interview, the question was: "What are the requirements for volatile variables?" I mean, why it's all necessary and what makes it clear, and I couldn't find a specific answer about the demands.



  • If 2 flows are read and written in variables, only volatile Not enough. There is still a need to use synchronization to guarantee the atomaricity of reading and recording. Another reason. volatile Performance suffers because the meaning is written and read straight to memory by blowing the kash, which is expensive. I mean, you shouldn't. volatile In places where performance is important.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2