My library to send refs between threads

I have suggested that stdlib misses the feature to send refs to non-Send objects between threads using mutexes and proposed a change:

unsafe impl<'mutex, T: ?Sized + Sync> Sync for Mutex<'mutex, T> {}
unsafe impl<'mutex, T: ?Sized> Send for Mutex<'mutex, T> { }

I also showed my library with class RefMutex as a workaround.

Are my

  • proposed changes to stdlib
  • my workaround library

This would let you send any value to another thread by wrapping it in a Mutex<Option<T>>, sending the mutex to the other thread, and taking the value out of the Option by replacing the Option with None.


(In other words, as was already pointed out in that IRLO thread, neither your proposed changes to std nor your workaround library are correct.)

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.