[gdal-dev] How to correctly initialize GDAL library in a multithreaded environment?

Even Rouault even.rouault at spatialys.com
Mon Jan 14 04:04:49 PST 2019


On lundi 14 janvier 2019 13:57:45 CET Константин Шпурик wrote:
> Thank you for the quick answer!
> 
> The version of GDAL is 2.2.3 and OS is Windows.
> 
> I'm using not the latest version, but I've checked the latest code and it
> seems like it will still reproduce for Windows for 2.5.0.
> 
> Yeah, I've found the ticket,

which one ?

> so I'll wait until fixed and will try to
> update to latest version.
> 
> Thanks,
> KS.
> 
> On Mon, Jan 14, 2019 at 1:16 PM Even Rouault <even.rouault at spatialys.com>
> 
> wrote:
> > Hi,
> > 
> > > I have a multithreaded application that uses GDAL. Generally it works
> > 
> > fine,
> > 
> > > but sometimes I have a hang when trying to create transformations from
> > > different threads.
> > > 
> > > Seems like race condition occures when initializing static CPLMutex
> > > *hConfigMutex located in gdal\port\cpl_conv.cpp file;
> > 
> > On which operating system and with which GDAL version ?
> > With recent enough GDAL versions, and on Linux/Unix, I believe that mutex
> > creation should now be thread-safe. But there might still be issues on
> > Windows. We should be able to fix that more easily with C++11 mutex now.
> > 
> > Please file a ticket about that on
> > https://github.com/OSGeo/gdal/issues with the above requested details.
> > 
> > > I was able to fix the issue by calling a function that initializes the
> > 
> > mutex
> > 
> > > before calls from different threads(just calling the following code:
> > > CPLGetConfigOption("GDAL_DATA", nullptr);) but it doesn't feel right.
> > 
> > Calling a function like GDALRegisterAll() that involves mutex creation
> > before
> > creating any thread has been the historical recommandation
> > 
> > Even
> > 
> > --
> > Spatialys - Geospatial professional services
> > http://www.spatialys.com


-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list