rustler icon indicating copy to clipboard operation
rustler copied to clipboard

impl Sync for OwnedBinary?

Open JayKickliter opened this issue 2 years ago • 3 comments

I have the need to share owned binaries across threads via RwLock. My hunch is that it's safe to implement Sync for OwnedBinary, but I haven't looked at these guts in quite some time.

JayKickliter avatar Jun 30 '22 16:06 JayKickliter

OwnedBinary is effectively a mutable buffer without internal synchronisation, how could it be Sync?

filmor avatar Jun 30 '22 21:06 filmor

For the same reason Vec<u8> is Sync despite it being a mutable buffer without internal synchronization: ownership rules will prevent mutating the OwnedBinary when it is shared.

JayKickliter avatar Jul 01 '22 16:07 JayKickliter

True, I checked again, as to be expected it doesn't have any interior mutability (wasn't completely sure about the realloc).

filmor avatar Jul 03 '22 13:07 filmor