Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的目标系统有支持 C++0x(但不支持 C++11)的 g++ 4.6.3。我正在使用 atomic_int 来存储我在两个线程之间访问的状态变量。但是,似乎没有为此类型定义不等于运算符。我如何比较 atomic_ints?
atomic_int由于' 的转换运算符,您应该能够直接比较它们。如果这不起作用,那么您只需要找到特定于编译器的解决方法。也许如果您显式转换它们或使用load()成员函数atomic_load()或非成员函数,它将起作用:
atomic_int
load()
atomic_load()
static_cast<int>(a) == static_cast<int>(b) a.load() == b.load() atomic_load(&a) == atomic_load(&b)
您应该注意,这不是任何类型的原子比较,因此请确保您没有尝试在此比较中做您不应该做的事情。