search

Home  >  Q&A  >  body text

java - volatile关键字的使用误区?

在tij中的volatile中有这么一句话:

当一个域依赖于它之前的值时(如自增), 那么volatile就无法工作了. 如果某个域的值受到其他域的值的限制, 那么volatile也无法工作, 例如Range类的lower和upper边界值必须遵循lower<=upper

这段话想要表达的意思是什么?

PHP中文网PHP中文网2809 days ago608

reply all(3)I'll reply

  • 怪我咯

    怪我咯2017-04-18 09:53:22

    In layman’s terms, values ​​marked as volatile may change unpredictably, so they cannot be cached and should be read from main memory each time.
    Auto-increment operation, this value may change between reading and writing, so the correct result cannot be written.
    Again, this value changes uncontrollably, so the invariant may not be satisfied.

    reply
    0
  • 迷茫

    迷茫2017-04-18 09:53:22

    It should be that volatilethe atomicity of the operation cannot be guaranteed

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:53:22

    See: The meaning of volatile keyword in java

    reply
    0
  • Cancelreply