Are memory-mapped files thread safe Are memory-mapped files thread safe multithreading multithreading

Are memory-mapped files thread safe


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).