4 ms·
so what's the 'Windows way' then? keeping a file open forever and let it lock out other programs from using that file? I'm starting to get an idea why Windows i
by m_mueller 6y ago
so what's the 'Windows way' then? keeping a file open forever and let it lock out other programs from using that file? I'm starting to get an idea why Windows is getting on my nerves so much with file locks....
- mehrdadn 6y agoYou can just use FILE_SHARE_WRITE if you don't want to lock out other programs...
- VBprogrammer 6y agoIf I know one thing about files it's that any fix beginning with "You can just..." is probably wrong. https://danluu.com/file-consistency/ https://danluu.com/file-consistency/
- mehrdadn 6y agoI didn't recommend you do this, I just said it's there if you really want to.
- for_xyz 6y ago> so what's the 'Windows way' then? Using either memory mapped files of overlapped io (IOCP). It's tricky to use when you want to write the content since you must preallocate the file before you start with the writing. Appending to file just doesn't work under NT kernel since WriteFile blocks even if you use overlapped io. Devs just need different mentality when it comes to Windows programming compared to Linux. Due the fact that everything under NT kernel is operated asynchronously you'll have to adapt your code to such concept. Meanwhile under Linux you had no other alternative for nearly 30 years (io_uring and friends) so if you wanted to be portable with minimum OS specific code then you had to implement things in synchronous way or write two separate code paths for each OS. Guess which one is used in practice.
- pjmlp 6y agoHere is the thing, UNIX is the strange dude with advisory file locks, every other multiuser OS does the right thing to avoid file corruption.