Barrier
#gcc提供的内存屏障,会同时限制编译器和cpu对指令乱序优化__sync_synchronize()#只限制编译器不乱序优化#define barrier() __asm __volatile_("": : :"memory")#只限制编译器不优化某次的内存访问#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
原子指令
#gcc编译器提供的原子指令__sync_fetch_and_add(int *ptr, int num);__sync_fetch_add_sub(int *ptr, int num);...
锁
#glibc提供的pthread库int pthread_mutex_lock(pthread_mutex_t *m);int pthread_mutex_unlock(pthread_mutex_t *m);
对比
(注:Ratio对应始终周期)
- Best-case CAS:能命中高速缓存的CAS
- Best-case lock:能命中高速缓存的lock(需要lock/unlock,对应两个原子操作)
- CAS cache miss:未命中高速缓存的CAS
- Comms Fabric:I/O操作的延时
- Global Comms:电池波绕地球一周的延时

