我知道is_lock_free取决于硬件,但当我在ADT上使用它时,它返回int类型的false,但返回真。这怎么可能?
#include <iostream>
#include <atomic>
struct myType {
size_t ID{};
size_t to{};
};
int main() {
std::atomic<myType> i{ };
std::cout << "\n" << i.is_lock_free();
std::atomic j { 1};
std::cout << "\n" << j.is_lock_free();
}发布于 2020-03-03 00:12:47
可以为某些数据类型返回is_lock_free()为true,对于另一个数据类型返回false吗?
是的,它可以。显示的程序有可能输出0 1。
事实上,如果不是这样的话,那么函数就没有必要成为模板的成员了。
https://stackoverflow.com/questions/60498294
复制相似问题