[Proj] libproj4 thread safety
Glynn Clements
glynn at gclements.plus.com
Sat Apr 23 21:22:55 EDT 2005
Gerald Evenden wrote:
> 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.
Exactly.
> > 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 ;-( )
No, I didn't do a final quality-control pass on my message.
The static proj_errno_location() was originally intended to be an
initialisation function, to be called from the exported
proj_errno_location(). Then I merged the two, and forgot to delete the
second one and forgot to remove the "static" from the first.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the Proj
mailing list