Possibility to make BiMap Send + Sync
Closed this issue · 1 comments
Lukazoid commented
As BiMap
uses Rc
internally it currently doesn't auto-impl Send
or Sync
, this means that even with the use of sync types (e.g. Mutex) it cannot be accessed from multiple threads.
Instead of using Arc
to achieve this, as the Rc
is never publicly exposed and its counter is only modified in functions which take a mutable reference or ownership (so concurrent access isn't an issue), would it be safe to simply impl Send and Sync for BiMap like so:
unsafe impl<L: Send, R: Send> Send for BiMap<L, R> {}
unsafe impl<L: Sync, R: Sync> Sync for BiMap<L, R> {}
I am currently after more input as to whether this would be safe to do but I cannot currently see any issues with the above.
Deleted user commented
I think you're right, I don't see any reason why BiMap
isn't already thread-safe. I'll make this change ASAP. Thanks!