我正在尝试 C++ 原子std::atomic<T>::is_always_lock_free和std::atomic<T>::is_lock_free.
我写了一个简单的结构体A,想知道 的原子版本是否A是无锁的:
#include <iostream>
#include <atomic>
using namespace std;
struct A {
int x;
int y;
int z;
};
int main() {
atomic<A> b;
cout << boolalpha;
cout << "b.is_always_lock_free = " << b.is_always_lock_free << endl;
cout << "b.is_lock_free = " << b.is_lock_free() << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在x86-64 Linux上,我用g++ 9.4.0和C++17编译它,输出正常:
b.is_always_lock_free = false
b.is_lock_free = false
Run Code Online (Sandbox Code Playgroud)
然而,我也在我的Mac(ARM64 )上用clang++ 16.0.0编译它,输出很奇怪:
b.is_always_lock_free = true …Run Code Online (Sandbox Code Playgroud) 在 TensorFlow 的官方文档中,它们总是training=True在训练循环中调用 Keras 模型时通过,例如logits = mnist_model(images, training=True).
我试过了help(tf.keras.Model.call),它表明
Help on function call in module tensorflow.python.keras.engine.network:
call(self, inputs, training=None, mask=None)
Calls the model on new inputs.
In this case `call` just reapplies
all ops in the graph to the new inputs
(e.g. build a new computational graph from the provided inputs).
Arguments:
inputs: A tensor or list of tensors.
training: Boolean or boolean scalar tensor, indicating whether to run
the `Network` in training mode …Run Code Online (Sandbox Code Playgroud) 如果我需要使用数学库,我需要-lm在Linux中使用GCC时添加.但是在Windows上,当我在MinGW-w64中使用GCC时,我没有使用-lm它并且效果很好.
我知道有必要链接的原因libm.但我真的不知道为什么我可以在Windows中省略它?