#include <stdint.h>
#include <iostream>
using namespace std;
uint32_t k[] = {0, 1, 17};
template <typename T>
bool f(T *data, int i) {
return data[0] < (T)(1 << k[i]);
}
int main() {
uint8_t v = 0;
cout << f(&v, 2) << endl;
cout << (0 < (uint8_t)(1 << 17)) << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
g++ a.cpp && ./a.out
1
0
Run Code Online (Sandbox Code Playgroud)
为什么我得到这些结果?
float a[4] = {1,2,3,4}, b[4] = {4,3,2,1};
uint32_t c[4];
int main() {
__m128 pa = _mm_loadu_ps(a);
__m128 pb = _mm_loadu_ps(b);
__m128 pc = _mm_cmpgt_ps(pa, pb);
_mm_storeu_ps((float*)c, pc);
for (int i = 0;i < 4; ++i) printf("%u\n", c[i]);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
什么是正确的指示_mm_storeu_ps((float*)c, pc)?在这里,c是一个整数数组......我不认为这种方式是好的,还是更好吗?
t0 = [[]] * 2
t1 = [[], []]
t0[0].append('hello')
print t0
t1[0].append('hello')
print t1
Run Code Online (Sandbox Code Playgroud)
结果是
[['hello'], ['hello']]
[['hello'], []]
Run Code Online (Sandbox Code Playgroud)
但我无法区分它们.
在linux代码中,我记得听说mutex_lock()周围有一个完整的内存障碍.我想确定它是否也在sem_xxx附近.
看到这个Singleton实现:
if not hasattr(Singleton, "_instance"):
with Singleton._instance_lock:
if not hasattr(Singleton, "_instance"):
Singleton._instance = Singleton()
return Singleton._instance
Run Code Online (Sandbox Code Playgroud)
似乎"Singleton._instance = .."(类似于setattr)和hasattr是原子的.或者hasattr不会因为setattr而导致崩溃.
但我无法找到任何支持上面'似乎'.
Linux 操作系统中 /proc/net/protocols 中的统计信息是什么意思?
cat /proc/net/protocols
protocol size sockets memory press maxhdr slab module cl co di ac io in de sh ss gs se re sp bi br ha uh gp em
PACKET 888 0 -1 NI 0 no kernel n n n n n n n n n n n n n n n n n n n
UNIX 752 40 -1 NI 0 yes kernel n n n n n n n n n n n n …Run Code Online (Sandbox Code Playgroud) 对于原始人,我认为这是必要的. 即使是非原始的,例如数组,我认为这也是必要的.
没有不稳定:
int d[2];
Run Code Online (Sandbox Code Playgroud)
线程1:
while (d[1] > 0) modify(d[0]);
Run Code Online (Sandbox Code Playgroud)
线程2:
while (d[0] > 0) modify(d[1]);
Run Code Online (Sandbox Code Playgroud)
我担心编译器会在没有volatile的情况下更改我的代码.while(true)modify();
所以我在'int d [2]'之前放了volatile; 但是我觉得有点奇怪,一切都装饰着挥发性.