On Tue, Jan 10, 2017 at 03:12:41PM +0000, Joao Von wrote:
> How Lua iteracts with "opportunistic locking" in Windows?
> I have worked with multi process environment sharing files but sometimes I
> receive a unexpected EOF reading a file.
> Thank you!
Lua's I/O module only uses the standard C API--fopen, fread, etc. It doesn't
even allow passing non-standard open mode flags to fopen. So the short
answer is that Lua doesn't know anything about file locking on any platform,
and the behavior you're seeing is a result of the default semantics
implemented by the Windows C runtime.
The exception is that the Lua 5.3 implementation can use the POSIX routine
getc_unlocked instead of getc. However, "unlocked" pertains to the
synchronization of threads sharing the same C FILE handle object, not the
kind of locking typically meant when discussing file locking on Windows or
Hopefully somebody else will explain more about the behavior you're seeing,
and what Window's APIs or third-party Lua modules you might want to
investigate. I'm not at all familiar with the details of file locking on