2021年3月17日

摘要: x86平台 CompareAndSwap实现如下所示 #define barrier() __asm__ __volatile__("": : :"memory") int CompareAndSwap(volatile int* ptr, int old_value, int new_value) 阅读全文
posted @ 2021-03-17 17:50 tycoon3 阅读(282) 评论(0) 推荐(0)
摘要: 单核 vs 多核 从多核的视角上来说,是存在着乱序的可能的。比如,假设存在变量x = 0,cpu0上执行写入W0(x, 1),对x写入1。接着在cpu1上,执行读取R1(x, 0),得到x = 0,这在x86和arm/power的cpu上都是可能出现的。原因是x86上cpu核和cache以及内存之间 阅读全文
posted @ 2021-03-17 17:42 tycoon3 阅读(1558) 评论(0) 推荐(0)
摘要: gcc 编译为汇编代码 原始C++代码如下: #include<atomic> using namespace std; atomic<int> a; int j; int main() { int n; a.store(1,memory_order_acquire); n = j; return 阅读全文
posted @ 2021-03-17 16:20 tycoon3 阅读(670) 评论(0) 推荐(0)

导航