[Proj] threadsafety and PROJ.4 - the projCtx API Update

support.mn at elisanet.fi support.mn at elisanet.fi
Fri Jun 11 01:52:07 EST 2010


Hello,

Frank, it is ok as long as you keep it downward compatible.
We mostly just call proj-4 from within a single thread so
we don't usually have any problems.

Regards: Janne

------------------------------------

Frank Warmerdam [warmerdam at pobox.com] kirjoitti: 
> Folks,
> 
> For a project I'm involved in (a spatial capability for Ingres), it is
> desirable to make PROJ.4 threadsafe.  In the past some work has been
> done to protect some parts of PROJ.4 with mutexes (ie. grid loading
> code).  However, at least one major hole remained in the thread safety
> of the library, and that was the use of "pj_errno" as a global error
> variable.  It is not only used to report to the application, but also
> for various internal checks.
> 
> I have struggled for a while with how to address this, and I have decided
> to implement a sort of thread context structure in PROJ.4 called projCtx.
> It includes a "last error" variable which is intended to replace use of
> pj_errno within the library and for applications that wish to support
> multi-threading.
> 
> I have written up a page on this, and just committed preliminary
> implementation of this structure.
> 
>    http://trac.osgeo.org/proj/wiki/ThreadSafety
>    http://trac.osgeo.org/proj/changeset/1854
> 
> The short story is that applications which don't care about thread safety
> can continue to call the API as they do now.  Those that do care, can create
> a projCtx with pj_ctx_alloc(), and then call pj_init_ctx() or
> pj_init_plus_ctx() with that context.  These functions push a pointer to
> the context into the projPJ structure so it is not necessary to be aware
> of the context in other parts of the high level API.
> 
> I must confess I've just gone ahead and done this without seeking
> permission, but if there are strong reasons not to use this approach
> I'd consider backing it out in favor of another solution.   So I'm seeking
> feedback on the approach and if anyone sees other problems.
> 
> Best regards,
> -- 
> ---------------------------------------+--------------------------------------
> I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
> light and sound - activate the windows | http://pobox.com/~warmerdam
> and watch the world go round - Rush    | Geospatial Programmer for Rent
> 
> _______________________________________________
> Proj mailing list
> Proj at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/proj
> 



More information about the Proj mailing list