__asm__ __volatile__("": : :"memory")

__asm__ __volatile__("": : :"memory")

memory强制gcc编译器假设RAM所有内存单元均被汇编指令修改,这样cpu中的registers和cache中已缓存的内存单元中的数据将作废。cpu将不得不在需要的时候重新读取内存中的数据。这就阻止了cpu又将registers,cache中的数据用于去优化指令,而避免去访问内存。

这里就是跟gcc说已经更改了你存了

详细请参看:

http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=1978940

http://gcc.gnu.org/onlinedocs/gcc-4.4.0/gcc/Extended-Asm.html#Extended-Asm

http://hi.chinaunix.net/?uid-20359379-action-space-mode-fav-page-2

其中需要参看Linux内核内存屏障

http://bbs.chinaunix.net/thread-1952658-1-1.html   Linux内核内存屏障
http://bbs.chinaunix.net/thread-1952658-1-1.html  
http://www.linuxidc.com/Linux/2011-10/44623.htm

原文地址:https://www.cnblogs.com/moonflow/p/2300251.html