Volatile Violates its main job?

前端 未结 3 1175
栀梦
栀梦 2020-12-14 17:09

According to MSDN:

The volatile keyword indicates that a field might be modified by multiple threads that are executing at the same time. Fields tha

3条回答
  •  借酒劲吻你
    2020-12-14 17:33

    Another point raised by Joseph Albahari is that process architecture can adversely impact volatile, i.e. AMD in particular can cause values to be swapped.

    Since you will probably have no idea what system type your application will run on in production its best to always avoid the volatile keyword.

    Also slightly off topic you should always avoid the ReaderWriterLock class as under heavy load on multiprocessor systems this can allow multiple write locks please see here to be taken simultaneously which will cause application hangs which will be extremely difficult to root cause

提交回复
热议问题