How can I wake up one process from the wait queue?

Pranay Srivastava pranjas at gmail.com
Thu Oct 30 04:56:03 EDT 2014


Hi

You got to use exclusive wait queues here. Needs a bit more lines but
you can specify exactly how many tasks you want woken up.

You should be able to look it up easily on how to use it.

On Thu, Oct 30, 2014 at 2:02 PM, Rock Lee <rocklee_104 at sina.com> wrote:
> Hi, everyone
>
> I am implementing a simple driver to experiment with wait queue.Two or more
> read processes block until a write process changes a flag and call
> wake_up_interruptible().I expect that a write process will only wake up one
> read process.However, once a write process calls  wake_up_interruptible() ,
> all the read processes are awaken. How can I wake up one process from the
> wait queue? Here is the snippet of the simple dirver(just for experimenting,
> kernel 2.6.18):
>
>
> static ssize_t rlwait_read(struct file *filp, char __user *userp, size_t
> size, loff_t *off)
>
> {
>
>     struct rlwait_t *rock = (struct rlwait_t *)filp->private_data;
>
>     DECLARE_WAITQUEUE(wait, current);
>
>
>
>     add_wait_queue(&rock->r_wait_head, &wait);
>
>
>
>     while (rock->r_flag == 0) {
>
>         set_current_state(TASK_INTERRUPTIBLE);
>
>         schedule();
>
>     }
>
>
>     remove_wait_queue(&rock->r_wait_head, &wait);
>
>     set_current_state(TASK_RUNNING);
>
>     return 0;
>
> }
>
>
> static ssize_t rlwait_write(struct file *filp, const char __user *userp,
> size_t size, loff_t *off)
>
> {
>
>     struct rlwait_t *rock = (struct rlwait_t *)filp->private_data;
>
>
>
>     rock->r_flag = 1;
>
>     wake_up_interruptible(&rock->r_wait_head);
>
>
>
>     return size;
>
> }
>
>
> Thans in advice.
>
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>



-- 
        ---P.K.S



More information about the Kernelnewbies mailing list