volatile

作者: michael_0x | 来源:发表于2019-04-07 09:53 被阅读0次

    volatile only ensures sync from local cache to shared cache and make an variable visible to other threads. but won't ensure writing atomic as show below:

    image.png

    to fix this problem, adopt a concurrent tool to ensure only one thread can access the shared variable at one time:

    image.png

    or:

    image.png

    extend:

    image.png

    相关文章

      网友评论

          本文标题:volatile

          本文链接:https://www.haomeiwen.com/subject/izmjiqtx.html