Opened 11 years ago

Last modified 10 years ago

#5101 closed defect

GDALDataset::GetProjectionRef() blocking — at Initial Version

Reported by: Kosta Owned by: warmerdam
Priority: normal Milestone:
Component: GDAL_Raster Version: 1.9.2
Severity: normal Keywords:
Cc:

Description

It seems that the call to GDALDataset::GetProjectionRef() can sometimes block when used in a multi-threaded environment and used on a dataset opened twice and accessed from two different threads for certain datasets. Sample program to reproduce the behavior (sorry for the usage of boost threads):

const char RASTER_FILE[] = "D:/test.tif";

GDALDataset* const ds1 = static_cast<GDALDataset*>(GDALOpen(RASTER_FILE, GA_ReadOnly));
GDALDataset* const ds2 = static_cast<GDALDataset*>(GDALOpen(RASTER_FILE, GA_ReadOnly));

boost::thread thread1([&]() {
    std::cout << "#1: start calling GetProjectionRef() on thread #" << boost::this_thread::get_id() << std::endl;
    ds1->GetProjectionRef();
    std::cout << "#1: GetProjectionRef(): done" << std::endl;
    boost::this_thread::sleep_for(boost::chrono::seconds(30));
    std::cout << "#1: deleting DS" << std::endl;
    delete ds1;
    std::cout << "#1: DS deleted" << std::endl;
});

boost::thread thread2([&]() {
    boost::this_thread::sleep_for(boost::chrono::seconds(10));
    std::cout << "#2: start calling GetProjectionRef() on thread #" << boost::this_thread::get_id() << std::endl;
    ds2->GetProjectionRef();
    std::cout << "#2: GetProjectionRef(): done" << std::endl;
    std::cout << "#2: deleting DS" << std::endl;
    delete ds2;
    std::cout << "#2: DS deleted" << std::endl;
});

thread1.join();
thread2.join();

The call to GetProjectionRef() on the 2nd threads blocks until the 1st datasource object gets deleted by the 1st thread. You can observe the same behavior if you use a copy of the attached GeoTiff and open both datasets from the 2 different files. Maybe that is related to the not-found EPSG code used by the GeoTiff, which then holds on to an internal lock/mutex?

I haven't checked this with GDAL 1.10 yet...

Change History (1)

by Kosta, 11 years ago

Attachment: test.tif added
Note: See TracTickets for help on using tickets.