archlinux / alpm.rs

Rust bindings for libalpm
GNU General Public License v3.0
112 stars 21 forks source link

Missing `Send` impl for `Alpm`? #42

Open fosskers opened 5 months ago

fosskers commented 5 months ago

Hi there. Between major versions 2 and 3, the Alpm type lost its Send implementation. This prevents it from being passed to other threads, even when wrapped in lock types like in Arc<Mutex<Alpm>>. Was this change intentional, or am I overlooking something?

Thanks,

Colin

fosskers commented 5 months ago

For now, I have worked around this by tricking the compiler: https://github.com/fosskers/aura/blob/master/rust/r2d2-alpm/src/lib.rs#L35-L64

This works for my use cases. While indeed sharing a raw alpm::Alpm across threads does currently cause segfaults, using a connection pool as I'm doing works as intended.

Morganamilo commented 5 months ago

I did this like 3 years ago (been waiting to release V3 for a long time) so my memory is a bit fuzzy.

I think I'd need to re reason if it's safe or not. I think it may be safe if the callbacks were also bounded by send.

fosskers commented 5 months ago

The error messages were complaining a lot about the callbacks, but also about the NonNull that now wraps the inner alpm_handle_t.

Experimentally at least it seems to be safe not explode. Using a pool I'm able to have several open Alpm connections and use them with rayon, basically only for concurrent reads to the DB. I'm never calling anything requires &mut Alpm.

fosskers commented 5 months ago

For now Aura is fixed with the workaround, so there's no rush (on my end) for Send to be provided directly.