contextfree / winrt-rust

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

Figure out the story around Send and Sync #71

Open Boddlnagg opened 5 years ago

Boddlnagg commented 5 years ago

I haven't fully understood the Windows Runtime threading model yet. We should probably mark generated class as Send and/or Sync based on the ThreadingModel and MarshallingBehavior attributes. If I understand https://docs.microsoft.com/en-us/cpp/cppcx/threading-and-marshaling-c-cx?view=vs-2019 correctly, I think we could do the following:

I think we can mark a class as Sync if ThreadingModel is Both or MTA, based on this sentence:

If you author a class that has ThreadingModel=Both or ThreadingModel=MTA, make sure that the class is thread-safe.

I think we can mark a class as Send if MarshallingBehavior is Agile, based on this sentence:

In the vast majority of cases, instances of Windows Runtime classes, like standard C++ objects, can be accessed from any thread. Such classes are referred to as "agile"

It would be great if someone with more understanding could confirm these assumptions.

Related: #63, #18, #62, #60