本文介绍了使用wait_event_interruptible和wake_up_all在一起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于涉及使用阻塞和锁调度流程一类项目,我们应该使用两个内核函数:

  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在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 11:10