Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 是否必须从系统调用调用down(信号量)和down_intterruptible(信号量)?_Linux_Linux Kernel_Semaphore_Interrupt Handling_Interrupt - Fatal编程技术网

Linux 是否必须从系统调用调用down(信号量)和down_intterruptible(信号量)?

Linux 是否必须从系统调用调用down(信号量)和down_intterruptible(信号量)?,linux,linux-kernel,semaphore,interrupt-handling,interrupt,Linux,Linux Kernel,Semaphore,Interrupt Handling,Interrupt,有人问我是否可以使用以下功能: void down(struct semaphore* sem); int down_intterruptible(struct semaphore* sem); 仅从系统调用?不,它们可以从允许您睡眠的任何内核上下文中使用。例如,内核线程可以执行down()。当然计时器函数不能,因为down()可能会休眠。您肯定不需要直接处理系统调用 另一方面,在现代内核中,struct mutex和mutex\u lock()优于struct semaphore和down(

有人问我是否可以使用以下功能:

void down(struct semaphore* sem);
int down_intterruptible(struct semaphore* sem);

仅从系统调用?

不,它们可以从允许您睡眠的任何内核上下文中使用。例如,内核线程可以执行
down()
。当然计时器函数不能,因为
down()
可能会休眠。您肯定不需要直接处理系统调用


另一方面,在现代内核中,
struct mutex
mutex\u lock()
优于
struct semaphore
down()
,除非您确实需要计算信号量,或者需要从与获取信号量不同的上下文中释放信号量。

不一定。您可以尝试从内核的任何位置锁定信号量,但中断上下文除外。未能获取信号量将使您的任务处于休眠状态,并且您负担不起将中断处理程序置于休眠状态并导致死锁

你可以用