All of lore.kernel.org
 help / color / mirror / Atom feed
* How can I wake up one process from the wait queue?
@ 2014-10-30  8:32 Rock Lee
  2014-10-30  8:52 ` Raghavendra
  2014-10-30  8:56 ` Pranay Srivastava
  0 siblings, 2 replies; 3+ messages in thread
From: Rock Lee @ 2014-10-30  8:32 UTC (permalink / raw)
  To: kernelnewbies

Hi, everyoneI 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20141030/b8749aec/attachment.html 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* How can I wake up one process from the wait queue?
  2014-10-30  8:32 How can I wake up one process from the wait queue? Rock Lee
@ 2014-10-30  8:52 ` Raghavendra
  2014-10-30  8:56 ` Pranay Srivastava
  1 sibling, 0 replies; 3+ messages in thread
From: Raghavendra @ 2014-10-30  8:52 UTC (permalink / raw)
  To: kernelnewbies

On Thursday 30 October 2014 02:02 PM, Rock Lee 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?
>
You can use exclusive wait queues, which wakes up only one process from 
the queue.

Although the general idea that is followed is: all the process are woken 
up once the resource is made available. And then the access to that 
resource is guarded by a lock, which in turn allows only one process to 
access the resource. Rest of the processes are pushed backed to sleep(or 
busy wait).

-------------------------------------------------------------------------------------------------------------------------------
[ C-DAC is on facebook. Kindly follow us on the following url:  https://www.facebook.com/CDACINDIA ]

This e-mail is for the sole use of the intended recipient(s) and may
contain confidential and privileged information. If you are not the
intended recipient, please contact the sender by reply e-mail and destroy
all copies and the original message. Any unauthorized review, use,
disclosure, dissemination, forwarding, printing or copying of this email
is strictly prohibited and appropriate legal action will be taken.
-------------------------------------------------------------------------------------------------------------------------------


-------------------------------------------------------------------------------------------------------------------------------
[ C-DAC is on Social-Media too. Kindly follow us at:
Facebook: https://www.facebook.com/CDACINDIA & Twitter: @cdacindia ]

This e-mail is for the sole use of the intended recipient(s) and may
contain confidential and privileged information. If you are not the
intended recipient, please contact the sender by reply e-mail and destroy
all copies and the original message. Any unauthorized review, use,
disclosure, dissemination, forwarding, printing or copying of this email
is strictly prohibited and appropriate legal action will be taken.
-------------------------------------------------------------------------------------------------------------------------------

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20141030/17b12418/attachment.html 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* How can I wake up one process from the wait queue?
  2014-10-30  8:32 How can I wake up one process from the wait queue? Rock Lee
  2014-10-30  8:52 ` Raghavendra
@ 2014-10-30  8:56 ` Pranay Srivastava
  1 sibling, 0 replies; 3+ messages in thread
From: Pranay Srivastava @ 2014-10-30  8:56 UTC (permalink / raw)
  To: kernelnewbies

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@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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-10-30  8:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-30  8:32 How can I wake up one process from the wait queue? Rock Lee
2014-10-30  8:52 ` Raghavendra
2014-10-30  8:56 ` Pranay Srivastava

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.