contextfree / winrt-rust

Use and (eventually) make Windows Runtime APIs with Rust
Apache License 2.0
142 stars 10 forks source link

`RuntimeContext` should not be `Send` or `Sync` #60

Closed rbtying closed 5 years ago

rbtying commented 5 years ago

RuntimeContext is a wrapper around RoInitialize and RoUninitialize, which initialize (and uninitialize) the WinRT runtime per thread.

Calling RoUninitialize from a different thread than RoInitialize is not allowed.

To fix this, we can replace the inner () with PhantomData<*mut ()>, which is also a zero-size type and (by virtue of containing a pointer) is not automatically Send and Sync. In the future (i.e. when more stuff is stablized), we can explicitly do impl !Send for RuntimeContext.

Boddlnagg commented 5 years ago

Thanks! Would you like to prepare a PR? Issue #18 is also about RuntimeContext, maybe you have some ideas there as well?

rbtying commented 5 years ago

Yup, I'll send something over when I get a chance -- ran across this while looking at the landscape for COM things in Rust, and haven't finished setting everything up yet (CoInitialize has the same issue, haha).

c.f. #18, I think that will require more reading / playing with types to get right. Worth doing, but needs more thought.