Volatile and CreateThread

前端 未结 6 459
借酒劲吻你
借酒劲吻你 2020-12-06 07:52

I just asked a question involving volatile: volatile array c++

However my question spawned a discussion on what volatile does.

Some claim that w

6条回答
  •  我在风中等你
    2020-12-06 08:54

    volatile IS NOT a synchronisation mechanism. It DOES NOT guarantee atomicity nor ordering. If you cannot guarantee that all operations performed on a shared resource are atomic, then you MUST use proper locking!

    Finally, I highly recommend reading these articles:

    1. Volatile: Almost Useless for Multi-Threaded Programming
    2. Should volatile Acquire Atomicity and Thread Visibility Semantics?

提交回复
热议问题