我最近正在阅读Linux内核开发,我有一些与禁用抢占相关的问题.
在第7章的"中断控制"部分,它说:
此外,禁用中断还会禁用内核抢占.
我还从书中读到,在以下情况下可能会发生内核抢占:
当中断处理程序退出时,返回内核空间之前.
当内核代码再次成为可抢占状态时.
如果内核中的任务显式调用schedule()
如果内核中的任务阻塞(导致调用schedule())
但我无法将禁用中断与这些情况联系起来.
据我所知,自旋锁将使用preempt_disable()函数禁用抢占.
帖子究竟什么是"自旋锁"? 说:
在单核心机器上,自旋锁只是"禁用中断"或"引发IRQL",这完全阻止了线程调度.
preempt_disable()是否通过禁用中断来禁用抢占?
我是C++的新手,我有一些不清楚的地方:
#include <iostream>
using namespace std;
double* foo(void)
{
double* b = new double[100];
return b;
}
int main()
{
double* a = foo();
delete [] a;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这段代码有问题吗?我的意思是我使用operator delete的方式是否正确?我指向foo函数中指向已分配内存的指针b指向外部foo,我可以通过delete [] a释放内存吗?我不知道编译器如何计算执行delete []时要释放的字节数.谢谢
我读了一些相关的帖子:
(1)来自Robert Love:http://permalink.gmane.org/gmane.linux.kernel.kernelnewbies/1791
You cannot sleep in an interrupt handler because interrupts do not have a backing
process context, and thus there is nothing to reschedule back into. In other
words, interrupt handlers are not associated with a task, so there is nothing to
"put to sleep" and (more importantly) "nothing to wake up". They must run
atomically.
Run Code Online (Sandbox Code Playgroud)
If sleep is allowed, then the linux cannot schedule them and finally cause a
kernel panic with …Run Code Online (Sandbox Code Playgroud)