Le mar. 30 déc. 2025, à 13 h 28, Even Rouault via Tiff <[email protected]>
a écrit :

> I'm a bit unusure about the thread-safey aspects of your proposal, in
> particular about the need for a mutex per TIFF handle. I would argue
> that's the job of the caller to protect that. One option could be to
> have a opt-in mutex (a bit like SQLite3's  SQLITE_OPEN_NOMUTEX vs
> SQLITE_OPEN_FULLMUTEX : https://sqlite.org/c3ref/open.html).  Having
> some higher level APIs that for example extract from multi-strip/tiles
> at once and may use multithreading internally to decode several
> tiles/strips in parallel would have strong value though (something I do
> on the GDAL side of the TIFF reader typically).
>

Good thread safety is not about adding mutexes, it's about separating
resources so multiple threads can work without the need for locking.

What we need the most is easy access to multithread tile/strip
encoding/decoding. Meaning we need APIs to be able to create multiple codec
instances for a single TIFF file. I've done this manually with
TIFFReadRawTile()/TIFFWriteRawTile() in the past but it's a pain as each
supported codec needs to be reimplemented outside libtiff. It does not
fundamentally require locking inside libtiff however, just some new APIs.

A separate nice thing to have is actual multithread I/O of tiles/strips
(pread()/pwrite() or similar). Reading especially. Writing is less valuable
in my experience, and more complex. I think reading can be done without a
mutex with some care, but one may be desirable to ensure safe use. Writing
certainly requires one.

Layering a simple "read/write this file using multiple threads" API on top
of this is also desirable as it is what many users will want out of libtiff.

Wrapping a TIFF handle around a big mutex to make everything safe seems of
low value to me. That can easily be done by user code if that's how they
want to deal with multiple threads.

Olivier
_______________________________________________
Tiff mailing list
[email protected]
https://lists.osgeo.org/mailman/listinfo/tiff

Reply via email to