[英]Can I place a std::atomic<int64> in shared memory and expect atomic operation?
Does std::atomic play well in shared memory, or is it undefined? std::atomic 在共享内存中运行良好,还是未定义? It seems like an easy way to add lockless basic types to shared memory however I could believe that it's not possible to guarantee atomic behaviour in the context of shared memory.将无锁基本类型添加到共享内存似乎是一种简单的方法,但是我相信在共享内存的上下文中不可能保证原子行为。
为什么不呢,你只需要在共享内存区域内正确分配和构造它。
It depends.这取决于。
If the architecture you are using supports atomic operations on 64-bit types, I would expect it to work.如果您使用的架构支持 64 位类型的原子操作,我希望它能够工作。 If std::atomic
is simulating atomic operations with mutexes then you will have a problem:如果std::atomic
使用互斥体模拟原子操作,那么您将遇到问题:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.