[Proj] libproj4 thread safety

Gerald Evenden gerald.evenden at verizon.net
Sun Apr 24 10:00:24 EDT 2005

My problem is as a matter of how I (and potentially others) use
libproj4.  Like GSL (scientific library). I make the *.a and store it in
/usr/local/lib, etc. and simply refer to it as '-l gsl' on the compile 
Thus, if pj_errno.o is part of libproj4.a then there is a problem as to
whether it is or is not thread friendly---is '-l proj4' required to be 
by '-l pthread'?  On my system, libproj4 is compiled with the GSL option
so I must always include a -l gsl when using libproj4 even though I may
not be using the projection that uses gsl.  Note that this can also be
the case with pthread as the the pthread pj_errno code works without 
using threads (a trivial amount of computational overhead).

Oh, headaches!  So many decisions.

1) make two libraries: libproj4.a libthproj4.a
2) three libraries: libproj4.a pj_errno.a pj_errno_th.a
3) require appropriate version of pj_errno.o on compile(link) line.

Note: compile flag for using threads is only required by pj_errno.c.  NO
other routine nor header file is involved.

An additional note can be made about this thread business and libproj4.
At the moment it appears that one can "open" a projection and make the
pointer returned by pj_init global so that it can be used by any thread
with pj_fwd and pj_inv calls.  The latter calls do not modify the 

On Apr 23, 2005, at 10:13 PM, Glynn Clements wrote:

> 	...

> Next problem is how to handle this procedure for both those
>> interested in threads and those not caring a whit.  If it
>> is placed in libproj4.a, users have to link with '-l threads'
>> regardless of using threads.  Make two different libraries?
>> Do not include pj_errno.o library and force user to include
>> pj_errno.o on compile line?  Note: I will include a compile
>> switch to allow for compiling as either a vanilla or pthreads
>> version---it makes no difference to the macro inclusion nor
>> the remainder of the libproj4 system.
>> Comments, suggestions would be appreciated here.
> One possibility is to put all of the pthread code into a separate
> source file, and conditionalise the pj_errno definition, e.g.:
> 	#define pj_errno (*pj_errno_loc())
> 	#else
> 	extern int pj_static_errno;
> 	#define pj_errno pj_static_errno
> 	#endif
> If the user compiles without PROJ_USES_PTHREADS, pj_errno_loc() will
> never be referenced, so the corresponding .o file from libproj.a won't
> get linked in, so there should be no references to the pthread
> functions in the final executable.
> 	...

> _____________________________________
Jerry and the low riders: Daisy Mae and Joshua.
"The whole religious complexion of the modern world is due to the
absence from Jerusalem of a lunatic asylum." Havelock Ellis, 1914

More information about the Proj mailing list