#define barrier() __asm__ __volatile__("": : :"memory")
The major of work is to enforce refresh the cache in cpu
CPU越过内存屏障后,将刷新自己对存储器的缓冲状态。这条语句实际上不生成任何代码,但可使gcc在barrier()之后刷新寄存器对变量的分配。
例1:
1 int a = 5, b = 6;
2 barrier();
3 a = b;
在line 3,GCC不会用存放b的寄存器给a赋值,而是重新读内存中的b值,赋值给a。
The other major purpose of barrier() is to synchronize two(or more) CPUs caches, it often used in SMP enviroment.
沒有留言:
張貼留言