Memory barrier vs Interlocked impact on memory caches coherency timing

前端 未结 3 1581
轮回少年
轮回少年 2020-12-29 08:26

Simplified question:

Is there a difference in timing of memory caches coherency (or \"flushing\") caused by Interlocked operations compared to Memor

3条回答
  •  無奈伤痛
    2020-12-29 08:51

    Short answer: CAS (Interlocked) operations have been (and most likely will) be the quickest caches flusher.

    Background: - CAS operations are supported in HW by single uninteruptable instruction. Compared to thread calling memory barrier which can be swapped right after placing the barrier but just before performing any reads/writes (so consistency guaranteed for the barrier is still met). - CAS operations are foundations for majority (if not all) high level synchronization construct (mutexes, sempahores, locks - look on their implementation and you will find CAS operations). They wouldn't likely be used if they wouldn't guarantee immediate cross-thread state consistency or if there would be other, faster mechanism(s)

提交回复
热议问题