Quantcast

Using libtiff in a multi-threaded context

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Using libtiff in a multi-threaded context

Dinesh Iyer
Hi,
I am developing an application to read TIFF files using libtiff and I am using multi-threading to improve performance. I was wondering if I can do query operations such as TIFFComputeTile/TIFFComputeTile/TIFFgetfield at the same time that I am calling TIFFReadEncodedStrip on a different thread. 

My other option is to "pause" the thread that is reading image data when a query such as that mentioned above is received.

Regards,
Dinesh

_______________________________________________
Tiff mailing list: [hidden email]
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Using libtiff in a multi-threaded context

Bob Friesenhahn
On Wed, 1 Mar 2017, Dinesh Iyer wrote:

> Hi,
> I am developing an application to read TIFF files using libtiff and I am
> using multi-threading to improve performance. I was wondering if I can do
> query operations such as TIFFComputeTile/TIFFComputeTile/TIFFgetfield at
> the same time that I am calling TIFFReadEncodedStrip on a different thread.

Libtiff does not do any locking internally.  It would be ideal if
libtiff is thread safe when using a thread per libtiff handle but
there are a few known issues such as related to error reporting.

> My other option is to "pause" the thread that is reading image data when a
> query such as that mentioned above is received.

It is not safe to access a libtiff handle from more than one thread at
once because the handle is stateful and it may be necessary to access
the file (possibly requiring a non-atomic seek plus read/write).  I
think that it is mostly safe if external locking assures that only one
libtiff function is invoked at once on the same handle.

Bob
--
Bob Friesenhahn
[hidden email], http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer,    http://www.GraphicsMagick.org/
_______________________________________________
Tiff mailing list: [hidden email]
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Using libtiff in a multi-threaded context

Roger Leigh
In reply to this post by Dinesh Iyer
On 01/03/2017 17:05, Dinesh Iyer wrote:
> Hi,
> I am developing an application to read TIFF files using libtiff and I am
> using multi-threading to improve performance. I was wondering if I can
> do query operations such as TIFFComputeTile/TIFFComputeTile/TIFFgetfield
> at the same time that I am calling TIFFReadEncodedStrip on a different
> thread.

See
https://github.com/ome/ome-files-cpp/blob/master/lib/ome/files/tiff/Sentry.cpp 
for my approach to tackling this.

- RAII sentry object to save and restore libtiff state, including error
handlers
- uses a recursive mutex so you can call functions which also create
their own sentries and lock the mutex
- traps libtiff errors and throws as exceptions


Note: I've not done any serious multi-threaded performance testing.  My
primary goal was safe error handling.  Might be useful for inspiration.
Or feel free to copy (it's BSD licensed).
_______________________________________________
Tiff mailing list: [hidden email]
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
Loading...