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

2006.09.22 17:49 "RE: [Tiff] libjpeg", by Philip Watkinson


I just did some searching on the Internet and found the following from March 2000:

libjpeg is thread-safe as long as (a) you don't have multiple threads operating concurrently on the same jpeg object, and (b) your underlying C library (particularly malloc/free) is thread-safe. You can have multiple jpeg objects being manipulated concurrently by different threads.

regards, tom lane
organizer, Independent JPEG Group


Cc: Philip Watkinson; tiff@lists.maptools.org Subject: Re: [Tiff] libjpeg

Is libjpeg thread safe?

An often debated question, but in my opinion `no'. The only safe way to use it is under a lock.

Are you claiming a lock is necessary for serializing all LibJpeg usage, or a lock is necessary per decoding/encoding session? In either of these cases, what exactly do you think is the unsafe stuff?

The problem is with the dependence on setjmp/longjmp for error recovery. These APIs were never designed with multi-thread in mind and are not thread safe on many (most?) platforms. Unless specifically documented to be thread safe, one must assume not thread safe for these APIs. Other than this, I think that libjpeg is pretty thread safe. Libpng has the same problem as libjpeg.