<!DOCTYPE html><html><head><title></title><style type="text/css">p.MsoNormal,p.MsoNoSpacing{margin:0}</style></head><body><div style="font-family:Arial;">Hi,<br></div><div style="font-family:Arial;"><br></div><div>On Sat, Sep 7, 2024, at 01:34, Even Rouault via gdal-dev wrote:<br></div><blockquote type="cite" id="qt" style=""><p>I just don't see how to do that. Even a mutex around file
operations would not be sufficient since we'd want both
Seek()+Read() to be atomic per thread. PRead() would solve that,
but very few drivers or underlying libraries use PRead() (and
there's no implementation of it for all file systems, like Windows
file API which lacks it). Or one would need a VSIThreadSafeHandle
that would maintain a per-thread position, but that would still
involves locking around access to the underneath handle.<br></p></blockquote><div style="font-family:Arial;">Coming back to this, there are two ways to get something similar to pread() on Windows:<br></div><div style="font-family:Arial;"><br></div><div style="font-family:Arial;"> - passing an OVERLAPPED struct to ReadFile without setting FILE_FLAG_OVERLAPPED. This is still synchronous [1], but reads from the offset you've specified. Unlike pread(), it updates the file pointer position on return, so it doesn't mix well with concurrent reads that don't pass in an offset.<br></div><div style="font-family:Arial;"> - mapping the file in memory and implementing it with memcpy(). It does incur an extra copy vs. pure mmap, but I don't think it's too bad [2]. Unfortunately, it's not great on 32-bit systems [3].<br></div><div style="font-family:Arial;"><br></div><div style="font-family:Arial;">Laurentiu<br></div><div style="font-family:Arial;"><br></div><div style="font-family:Arial;">[1] I don't want to be the one to open that can of worms<br></div><div style="font-family:Arial;">[2] I haven't used Windows in a while, but on Linux memcpy() uses SIMD, but copying memory between the kernel and the user doesn't<br></div><div style="font-family:Arial;">[3] Windows 11 dropped 32-bit CPU support, but 32-bit apps will still run<br></div><div style="font-family:Arial;"><br></div></body></html>