wio-rs icon indicating copy to clipboard operation
wio-rs copied to clipboard

Force Send+Sync on ComPtr

Open kvark opened this issue 6 years ago • 2 comments

We've been recently looking in depth at what Metal/Cocoa objects are Send+Sync in https://github.com/gfx-rs/metal-rs/issues/40. Our D3D12 backend in gfx-rs has a similar issue: a lot of unsafe impl Send/Sync for structures containing ComPtr.

What can be said about COM guarantees of thread safety?

This question also touches the problem that all ComPtr wrapped methods are &mut self, which automatically forbids any sharing (in safe code), even though we have examples (e.g. ID3D12Device) that are documented as thread-safe.

kvark avatar May 16 '18 14:05 kvark

In winapi 0.3 all interfaces take &self for their methods, not &mut self. As discussed in IRC quite a bit, COM thread safety is incredibly thorny due to some interfaces being thread safe and some not, as well as thread safety depending how the thread the object was created on was initialized for COM, and whether the thread you are sending the object to was initialized for COM in the right way as well. Since I can make zero guarantees about whether an arbitrary interface is thread safe, I cannot correctly impl Send or Sync for ComPtr.

retep998 avatar May 16 '18 22:05 retep998