Do properties have volatile effect?

后端 未结 6 1777
無奈伤痛
無奈伤痛 2021-02-19 10:54

In the code below will read1 be always equal to read2, provided property Flag can be changed from other threads? Concern here is that

6条回答
  •  深忆病人
    2021-02-19 11:13

    According to the documentation

    The volatile keyword indicates that a field can be modified in the program by something such as the operating system, the hardware, or a concurrently executing thread. ... Using the volatile modifier ensures that one thread retrieves the most up-to-date value written by another thread.

提交回复
热议问题