CreateFileMapping with multiple threads
im trying to use 2 threads running simultaneously and both using FileMapping feature to map a fil开发者_JAVA技巧e on memory via different handles. problem is the MapViewOfFile function sometimes allocates the mapping on both threads to the same offset of memory. i tried using mutex on those parts, but it seems after high usage i fail to write to the mapping location. tried using MapViewOfFileEx that gets a memory offset to use, but i dunno what offset should i provide it with. any help would be appreciated. thanks.
I ran a few tests and I don't get the same address for a mapped view unless both instances of the file mapping are marked read only, even if both views are mapped from the same file mapping object. The OS is going to map a view based on the process's address space, not based on which thread is opening the view. Can you show us the code that you are using to obtain your file handle, your file mapping handle, and your mapped view?
精彩评论