2004.11.04 18:31 "[Tiff] is libtiff thread-safe?", by James Xu

2004.11.05 12:50 "Re: [Tiff] is libtiff thread-safe?", by Joris Van Damme

How about this for solving both problems in one go...

Extend the TIFF data structure to contain a pair of function pointers to error and warning handling functions. When an error or warning occurs, see whether the relevant pointer is NULL, and if so just call the existing global function. If it's not NULL, then call the function from the TIFF structure instead, passing the TIFF* as an argument. I guess there's no need for specific user context for these functions, as the TIFFGet/SetClientInfo seems to cover it?

The option to set handlers per TIFF * is not necessary (though, of course, it doesn't hurt, either).

The only thing really necessary is a TIFF * as an argument to these handlers. That way, the handlers can indeed retrieve ClientInfo, and thus locate context.

Note that in none of the above the word 'thread' occurs. The assessment of the problem, and the proposed solution, does not change whether the scheme is multi-threading or not.

This was all discussed earlier... See http://www.asmail.be/msg0054965642.html for latest archived discussion, and http://www.asmail.be/msg0054815913.html for first archived discussion. The best solution proposed in these discussions is indeed the one you propose here. Passing TIFF * (or even directly ClientInfo) as an argument to the handlers, is similar to how it is done in LibJpeg, and every other library I can think of.

Joris Van Damme
Download your free TIFF tag viewer for windows here: