[gdal-dev] does gdal support multiple simultaneous writers to raster

Even Rouault even.rouault at mines-paris.org
Sat Jan 12 07:35:28 PST 2013


> ex. convert
> multiple datasets to different output datasets in a parallel way.

As Frank underlined, there's currently an issue with the global block cache 
regarding write support.

Imagine that you have 2 threads A and B.
Thread A deal with dataset A, and thread B deal with dataset .
Thread A is in the middle of writing some tile/line of dataset A.
Thread B is trying to fill a new entry in the block cache (with new read data, 
or new data to write). But the block cache is full. So the last recently used 
entry must be discarded. If that entry is a dirty block of dataset A, then it 
must be flushed to disk, in the context of thread B, but at that time thread A 
is also writing data... Which might be an issue since drivers are re-entrant 
(can be invoked by multiple threads, if each thread deal with different 
datasets) not thread-safe.

This specific case here could be fixed in different ways :
A) Making drivers thread-safe (or accessing them through a thread-safe layer), 
that is to say add a dataset level mutex
B) or having a per-dataset block cache instead of a global block cache
C) deal differently with dirty blocks. Only flush them if the operation that 
need to discard the dirty block is initiated by an operation on the same 
dataset as the dirty block.


> Would
> those parallel operations not be affected by GDAL caching for bot read and
> write.Since the cache is set to a limit. Is Accessing the current used
> cache value concurrent safeto increase it/decrease it ?

Hum, I see that GDALGetCacheMax() and GDALSetCacheMax() are not thread safe 
currently. We would need to protect them by the raster block mutex, with a 
leading call to CPLMutexHolderD( &hRBMutex );


More information about the gdal-dev mailing list