[Proj] libproj4 thread safety

Gerald Evenden gerald.evenden at verizon.net
Fri Apr 22 21:08:58 EDT 2005


OK, I think I understand it except for the detail below.

On Apr 22, 2005, at 6:03 PM, Glynn Clements wrote:

> 	....
file pj_error_stuff.c
#include <pthread>

// lot'sa stuff
> 	
> 	static int *proj_errno_location(void)
> 	{
> 	  void *p;
> 	  pthread_once(&proj_errno_key_once, proj_errno_key_create);
> 	  p = pthread_getspecific(proj_errno_key);
> 	  if (!p) {
> 	    p = malloc(sizeof(int));
> 	    pthread_setspecific(proj_errno_key, p);
> 	  }
> 	  return (int *) p;
> 	}
>
end of pj_error_stuff file.

You have the local (static) routine above which seems straight forward
and the global one below.

It would seem that if I put the above in a file (eventually for the 
library)
that the above routine should be global and executed safely in any
thread.  And, I might add, transparently to the using programmer.
That is, like an errno call.  The 'define' would be part of the 
lib_proj.h.

> 	int *proj_errno_location(void)
> 	{
> 	  return (int *) pthread_getspecific(proj_errno_key);
> 	}
>
I do not understand the inclusion of above procedure other than it 
eliminates
a few checks and setup and thus cannot be used as a first call.

Am I missing something?  (probably so ;-( )

Thanks for your help.

> 	#define pj_errno (*(*proj_errno_location()))
> 	....

> _____________________________________
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