关于自旋锁中忙等的疑问
我们知道在内核中,如果某个自旋锁暂时获取不到,就进入一个忙等阶段,大概的代码归纳为:
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.
应该是防止编译器给卡嚓掉的吧……