[英]std::atomic<std::shared_ptr<T>> is not working in C++20?
[英]Can I use C++20 `std::atomic<T>::wait()` or `std::atomic_flag::wait()` in shared memory?
我的項目涉及一個插件,以及一個用於所述插件的 GUI,該插件被隔離到一個單獨的進程中。 我分享的數據可能會被 GUI 更新,當它更新時,它應該由插件處理。
為此,我正在考慮將其放入我的共享內存塊中:
std::atomic_bool event_flag;
// insert mutex...
some_data_struct data;
本質上,當 GUI 想要更改數據時,它會執行以下操作:
// acquire mutex
// write data...
// release mutex
event_flag = true;
event_flag.notify_one();
然后插件執行以下操作:
event_flag.wait(true);
event_flag = false;
// acquire mutex
// read data...
// release mutex
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.