[gdal-dev] Multithreading with OGR

Frank Warmerdam warmerdam at pobox.com
Fri Jun 25 11:55:59 EDT 2010


Martin Dobias wrote:
> Hi Frank
> 
> On Wed, Jun 23, 2010 at 4:58 PM, Frank Warmerdam <warmerdam at pobox.com> wrote:
>> Martin,
>>
>> Generally speaking it is not safe to have multiple threads making calls
>> into a single OGRLayer at the same time.  At the very least you will
>> encounter the "messing up" effect on GetNextFeature(), even if you
>> serialize calls, and if you don't serialize the calls to the OGRLayer
>> you will also face potentially severe problems and crashes.
>>
>> With regard to RFC 16, only a little work in the existing code with
>> locks was implemented.  None of the TestCapability or GetLayerClone()
>> work was done.  I still think that the approach in the RFC is reasonable
>> but I don't currently have funding to pursue the matter.  There was
>> also some pushback at the time though I don't recall all the details.
> 
> My intent is to use two OGRLayer instances of the same layer: one
> instance for handling various stuff in main thread, the other one in
> worker thread for rendering. Can I expect the GetNextFeature calls to
> be reentrant, i.e. can they be called from both threads simultaneously
> using different instances of layers?

Martin,

Are the different OGRLayer instances coming from distinct OGRDataSource
instances? If so, yes, you could normally treat them as reentrant though
there might be a few special cases where that turns out not to be true.
Certainly this is only a good idea in read-only activities.

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



More information about the gdal-dev mailing list