IPC via mmap'ed file: should atomics and/or volatile be used?

拥有回忆 提交于 2019-12-06 08:27:28

You should not use volatile when changing an integer from more than one thread. Volatile is both not necessary and not sufficient. Atomic operations will do.

There is no guarantee that volatile will work correctly across multiple processors, the thing you need to check is whether that intrinsic inserts the appropriate memory barriers during the operation.

Is this some sort of semaphore? if so, you are better off using the platform implementation of such a construct.

No need for both volatile and atomic accesses. IPC using mmap works fine without them.

If you need to inform whether something changed, you can use message queues, but you can also use them instead of mmap (depends how big is the message you want to send. mmap works good is the data is big, but MQ is it is smaller then 200k)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!