Running a test on Linux gives the desired result. I notice these two warnings:
The page you're linking to has this warning: "If you use the std :: fstream / native file descriptor to write to a file when using file locks in this file, do not close the file before you release all file locks."
Boost::file_lock obviously uses LockFileEx on Windows. MSDN says the following: "If the lock process opens the file a second time, it cannot access the specified area through this second descriptor until it unlocks the region."
It seems that on Windows at least a file lock is for each descriptor, not for the file. As far as I can tell, this means that your program will fail under Windows.
source share