public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Tejun Heo <htejun@gmail.com>
To: Bo Yang <struggle@mail.nankai.edu.cn>
Cc: linux-kernel@vger.kernel.org
Subject: Re: sleep for ever ?
Date: Thu, 07 Sep 2006 12:01:09 +0200	[thread overview]
Message-ID: <44FFEDE5.3040902@gmail.com> (raw)
In-Reply-To: <357552113.05297@mail.nankai.edu.cn>

Hello, there.

Bo Yang wrote:
> Hi ,
>     Take a look at following code :
> 
> DECLARE_WAITQUEUE(wait, current);
> 
> add_wait_queue(q, &wait);
> while (!condition) {
>         /* if there is an interrupt here , and the interrupt
>            is just the one the sleeping process wait
>            for , is this process sleep for the interrupt
>            for ever ?*/
>         set_current_state(TASK_INTERRUPTIBLE);
>         if (signal_pending(current))
>                 /* handle signal */
>         schedule();
> }
> set_current_state(TASK_RUNNING);
> remove_wait_queue(q, &wait);
> 
> Suppose the process just want to sleep for an hardware
> event , but before the set_current_state() call , the event
> come , is the process sleep for ever ?

I guess you already know it but please try not to post the same message
multiple times.

And, yes, you're responsible to set task state *before* testing for the
sleeping condition and sleep.  In the above code, you can lose the wake
up event and thus sleep indefinitely.

-- 
tejun

  reply	other threads:[~2006-09-07 10:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <44FED70F.6080208@mail.nankai.edu.cn>
2006-09-06 14:11 ` sleep for ever ? Bo Yang
2006-09-07 10:01   ` Tejun Heo [this message]
     [not found] <44FED695.9030501@mail.nankai.edu.cn>
2006-09-06 14:09 ` 杨波
     [not found] <44FED63F.2090204@mail.nankai.edu.cn>
2006-09-06 14:07 ` 杨波

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=44FFEDE5.3040902@gmail.com \
    --to=htejun@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=struggle@mail.nankai.edu.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox