Thread safety of the reference count of a C++/CX WinRT pointer

前端 未结 1 1340
挽巷
挽巷 2021-01-26 20:42

I was under the impression that the reference count to WinRT objects was thread safe, given the use case. But I\'ve run into a bug that I don\'t know any other way to explain. F

相关标签:
1条回答
  • 2021-01-26 21:17

    Changes to the reference count of a ref class object are synchronized, but changes to a T^ object are not.

    You have two threads accessing _latest at the same time, and one of those threads is modifying _latest, so you need to synchronize access to _latest, e.g. using a std::mutex.

    0 讨论(0)
提交回复
热议问题