[Shapelib] is the shaplib library thread safe???

Frank Warmerdam warmerdam at pobox.com
Fri Nov 30 16:41:13 EST 2007


C S wrote:
> here i what concerns me. i am writing my own shapefile
> reader in C++ and i am at the point now to where i can
> use my .shp file and my .dbf file to take an area of
> interest(AOI) and get a "value" for like population or
> something for that AOI. 
> 
> we arent going to use ESRI for this but the client is
> going to have multiple AOI's that make up a bounding
> box. each 'cell' will have its own bounding area and
> thus will naturally get back different results. you
> can have 15 cells for instance with each its own AOI.
> 
> the idea is that every cell can fire off at once,
> probing the shapefile reader class i have created that
> will go out to the dbf file and return results. 
> 
> so what i am getting from you is that this is really
> not possible currently? 

C S,

It is not currently possible to have multiple threads calling
something like SHPReadObject() on the *same* SHPHandle.

I would suggest you just serialize access to shapelib with a
mutex.

Note that the disk can also only be reading in one place at a time,
so any sense that multiple threads could actually be reading the same
file at the same time is ultimately an illusion.

If the file isn't really all that huge you might also consider
reading it all into a memory structure and having your threads
scan that.  It could give large performance gains if done well
and if performance is important to you.

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    | President OSGeo, http://osgeo.org



More information about the Shapelib mailing list