当前位置: 代码迷 >> 驱动开发 >> 关于自旋锁中忙等的疑义
  详细解决方案

关于自旋锁中忙等的疑义

热度:12   发布时间:2016-04-28 10:39:07.0
关于自旋锁中忙等的疑问
我们知道在内核中,如果某个自旋锁暂时获取不到,就进入一个忙等阶段,大概的代码归纳为:

while (lock != 1) {
    __asm__ __volatile__("rep;nop": : :"memory");
}

查了一些资料也不太清楚rep;nop的作用,我想问的是,如果这里简单的写一个死循环会怎样,即:
while (lock != 1);

请大牛指点!谢谢
------解决思路----------------------

对于asm("":::"memory");手册上是这么说的,藏语不好……不解释……
Even the code part may be left empty, though an empty string is required. The next statement creates a special clobber to tell the compiler, that memory contents may have changed. Again, the clobber list will be explained later, when we take a look to code optimization.

应该是防止编译器给卡嚓掉的吧……
  相关解决方案