bczhc / bzip3-rs

Rust wrapper for bzip3 compression library
GNU Lesser General Public License v3.0
1 stars 1 forks source link

`Bz3Encoder` and `Bz3Decoder` do not implement `Send` and `Sync` #3

Closed marcospb19 closed 1 year ago

marcospb19 commented 1 year ago

I believe it should be safe to send (Send) bz3 encoder and decoders between different threads, as well as sharing immutable references (Sync).

For reference, here's the bzip2 code:

https://github.com/alexcrichton/bzip2-rs/blob/3032f3790742bffda521e54d14429f459e078eba/src/mem.rs#L13-L35

The type Stream implements Send and Sync so all decoders and encoders all auto-impl them too.

This is currently a blocker for #1, adding these lines was enough for me to make it work :) .

unsafe impl<W: std::io::Write> Send for Bz3Encoder<W> {}
unsafe impl<R: std::io::Read> Send for Bz3Decoder<R> {}
marcospb19 commented 1 year ago

I guess you can have your analogous version of Stream around *mut bz3_state, with a method like .as_ptr(), and have this struct implement Send and Sync.

But maybe calling it Bz3State instead of Stream :thinking: .

bczhc commented 1 year ago

:heavy_check_mark:

So far Bz3State is just a bz3_state wrapper. Later will add more associated methods on it, like bzip2 does. I will do some reading at bzip2-rs code...