georust / gdal

Rust bindings for GDAL
https://crates.io/crates/gdal
MIT License
339 stars 92 forks source link

Cannot share dataset safely between threads #522

Closed arya-pathak closed 4 months ago

arya-pathak commented 4 months ago

On trying to share the dataset object between multiple rayon threads for read/write operations, I get the following error: `*mut c_void` cannot be shared between threads safely within `{closure@src/lib.rs:218:19: 218:34}`, the trait `Sync` is not implemented for `*mut c_void` required because it appears within the type `&Dataset`

Using an Arc pointer along with a mutex introduces a lot of overhead and sometimes even slows down compared to the serial implementation. Is there any support for sharing a dataset between multiple threads safely?

cc: @rkshthrmsh

lnicola commented 4 months ago

GDAL doesn't support that: https://gdal.org/user/multithreading.html, see also #425.

ManeraKai commented 2 months ago

GDAL isn't thread-safe, but it is re-entrant. So, this ranyon code should be allowed:

  let test: Vec<Geometry> = (0..10)
        .into_par_iter()
        .map(|_| Geometry::from_wkt("POINT (10, 10)").unwrap())
        .collect();

right?