2006.09.22 14:20 "[Tiff] libjpeg", by Philip Watkinson

2006.09.22 17:31 "Re: [Tiff] libjpeg", by Joris Van Damme


Libtiff's tif_jpeg.c and tif_ojpeg.c are not thread safe due their use of setjmp()/longjmp(). These C APIs were defined long before programs used threads, and saving context may just plain not work. The assembly code used to save context can be quite arcane. For example, the referenced context (which also preserves all necessary CPU registers, including private ones) may be rendered incorrect due to operation of the thread scheduler. The CPU (or hardware thread context) used to throw the exception (via longjmp()) may not be the same as was used to save the context using setjmp(). As processor hardware continues to move forward toward multi-core/multi-thread the problem will just get worse.

Here, my comment on your other mail, that longjmp is not a part of LibJpeg but at most one of the options at the disposal of caller implementation, does not work, as longjump *is* a part of tif_jpeg and tif_ojpeg.

So I'm left with two questions

  1. Is the longjmp system really unsafe? I mean nowadays, on most systems, as opposed to being unsafe on one or two systems a decade ago.
  2. If this really is an issue, are exceptions a good alternative? Or do Linux guys not have exceptions? Are exceptions portable?

Best regards,

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