Are memory-mapped files thread safe

我的梦境 提交于 2019-12-05 11:08:20

You'll need to add the synchronization regardless if the MMF view is accessed from multiple processes or multiple threads inside one process. Fwiw, it doesn't make any sense to use an MMF for memory sharing inside one process. Threads already share the address space.

But does it apply to threads belonging to the same process?

Yes. If one thread changes part of the data in the mapping, then all other threads immediately see that change.

You need to ensure the threads coordinate their changes so no thread is accessing an inconsistent view (eg. all access is via a critical section).

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