[gdal-dev] GDALDataset blocks in different thread

Even Rouault even.rouault at mines-paris.org
Thu Sep 16 13:27:07 EDT 2010


James,

what you see is a bit surprising...

Do you build GDAL by yourself or use a packaged version ? If you build it 
yourself, you explicitely need to specify --with-threads at ./configure time 
(unless you use the latest trunk version where it is now the default). In 
port/cpl_multiproc.h, you can see #define CPL_MULTIPROC_PTHREAD 1 if everything 
works. If you have only the .so, you can for example try using the 
CPLCreateThread() method. If it returns -1, then you have the stub 
implementation.

Could you try compiling and running the following code that is an attempt to 
have a minimum scenario that reproduces what you descrbe ?

****************************************

#include <gdal.h>
#include <gdal_alg.h>
#include "cpl_multiproc.h"

void my_thread(void* pData)
{
    GDALDatasetH hDS;
    int checksum;  
    hDS = (GDALDatasetH)pData;
  
    printf("in thread\n");
    checksum = GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0, 20, 20);
    printf("checksum = %d\n", checksum);
}

int main(int argc, char* argv[])
{
    GDALDatasetH hDS;
    GDALAllRegister();
    hDS = GDALOpen("byte.tif", GA_ReadOnly);
    CPLCreateThread(my_thread, hDS);
    CPLSleep(2);
    printf("finished\n");
    return 0;
}

****************************************

It works fine for me. The byte.tif is available at 
http://trac.osgeo.org/gdal/export/20628/trunk/autotest/gcore/data/byte.tif

Otherwise, which OS are you using ?  which GDAL version ? Which GDAL driver is 
used by your dataset ? etc etc ? If you run it under gdb, what is the stack 
trace when it is blocked ?

Even

Le jeudi 16 septembre 2010 10:23:27, James Meyer a écrit :
> Hi
> 
> I am opening a GDALDataset in my main thread which I then pass to a
> second thread for processing. Only the second thread accesses the dataset.
> 
> As soon as the thread makes a call to GDALRasterBand::RasterIO() the
> thread blocks indefinitely.
> 
> Could you please explain to me why this is happening?
> 
> Also, how do I check whether my build of GDAL was built with the
> --with-threads option enabled?
> 
> Thanks
> 
> James
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev


More information about the gdal-dev mailing list