public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Mike Galbraith <efault@gmx.de>
To: Yitzchak Eidus <ieidus@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: puting task to TASK_INTERRUPTIBLE before adding it to an wait queue
Date: Fri, 17 Mar 2006 09:01:43 +0100	[thread overview]
Message-ID: <1142582503.7973.15.camel@homer> (raw)
In-Reply-To: <e7aeb7c60603161431m6d873520r2b6754e115e26f80@mail.gmail.com>

On Fri, 2006-03-17 at 00:31 +0200, Yitzchak Eidus wrote:
> the function worker_thread in kernel 2.6.15.6  first put the task to
> TASK_INTERRUPTIBLE and only then add itself to an wait queue:
> 	set_current_state(TASK_INTERRUPTIBLE);
> 	while (!kthread_should_stop()) {
> 		add_wait_queue(&cwq->more_work, &wait);

See dusty old archives...

http://www.ussg.iu.edu/hypermail/linux/kernel/9712.2/0545.html

<quote>
Anyway, the basic race-free wait loop looks like this (there are
variations, but this is one of the basic versions that you find in
various places):


if (should_wait_condition) {
add_wait_queue(..);
repeat:
current->state = TASK_UNINTERRUPTIBLE;
if (should_wait_condition) {
schedule();
goto repeat;
}
remove_wait_queue(..);
current->state = TASK_RUNNING;
}


There are only two important rules:
- you have to add yourself to the wait queue _before_ testing for the
condition.
- you have to mark yourself asleep _before_ testing for the condition.

</quote>


  parent reply	other threads:[~2006-03-17  8:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-16 22:31 puting task to TASK_INTERRUPTIBLE before adding it to an wait queue Yitzchak Eidus
2006-03-16 22:52 ` Yitzchak Eidus
2006-03-17  8:01 ` Mike Galbraith [this message]
2006-03-18  6:23   ` Andy Lutomirski

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=1142582503.7973.15.camel@homer \
    --to=efault@gmx.de \
    --cc=ieidus@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /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