edsrzf / mmap-go

A portable mmap package for Go
BSD 3-Clause "New" or "Revised" License
938 stars 129 forks source link

windows: Fix a race condition when removing file map handles. #7

Closed gilramir closed 8 years ago

gilramir commented 8 years ago

I'm writing a program with many simultaneous goroutines doing mmaps and munmaps, and ran into this problem.

We hold a lock on the handleMap while we remove an addr/handle pair from it, but we need to also include the UnampViewOfFile in the map. There was a window of opportunity for the OS to re-use the addr for a new map, and if the goroutine which mapped that addr also unmapped it before we tried to remove our handle from handleMap, we would find that our handle was missing from handleMap.

edsrzf commented 8 years ago

Thanks for the undoubtedly tough debugging and pull request!