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

前端 未结 1 1341
挽巷
挽巷 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)
提交回复
热议问题