问题描述
对于涉及使用阻塞和锁调度流程一类项目,我们应该使用两个内核函数:
INT wait_event_interruptible(wait_queue_head_t Q,条件);
无效wake_up_all(wait_queue_head_t * Q);
wait_event_interruptible的解释是:
And the explanation of wake_up_all is:
I'm having a hard time figuring out how exactly these functions work and how to use them together. For example, when does the CONDITION get checked? Does wait_event_interruptible continuously poll, or does it only recheck the condition when wake_up_all is called? This explanation is a little unclear.
If you could give an example of how to use these functions together that would be very helpful.
The whole point of a scheduler is to avoid polling in cases like this. What happens is precisely described in what you quoted : The condition is only rechecked on wake_up, ie for example if a given task is waiting for data to be produced :
consumer check if data is available
if not (ie condition false) it goes to sleepand is added to a wait queue
retry when waked up
While on the producer side
Once data is produced, set some flag, or add something to a listso that the condition evaluated by the consumer becomes true
call wake_up or wake_up all on a waitqueue
Now , I suggest you try to use them, and come back with another question AND code you tried if it does not work the way you want.
这篇关于使用wait_event_interruptible和wake_up_all在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!