mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Yitzchak Eidus <ieidus@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: question about code from the linux kernel development ( se ) book
Date: Fri, 21 Oct 2005 09:03:18 -0400 (EDT)	[thread overview]
Message-ID: <Pine.LNX.4.58.0510210848030.3903@localhost.localdomain> (raw)
In-Reply-To: <e7aeb7c60510210422s33c0240ex4eab1d90d94111fe@mail.gmail.com>


Oh God, please indent code examples, and if your email client strips white
space, change your email client.

On Fri, 21 Oct 2005, Yitzchak Eidus wrote:

> first i am very sorry if it isnt the place to ask questions like this
> but i didnt know where else to ask ( i tryed irc channels and i was
> send from there to this list )
> anyway:
> does this following code look buggy? :

[ Indention added ]

> DECLARE_WAITQUEUE ( wait , current );
> add_wait_queue ( q , &wait );
> while ( !condition ) {
>         set_current_stat ( TASK_INTERRUPTABLE ); i
>         if ( signal_pending ( current ) )
>                 /* handle signal */

I assume that the signal_pending is the if result and not the schedule.
Since there was no indentation I couldn't tell.

>         schedule ( );
/* Moved brace down added */
 }
> set_current_state ( TASK_RUNNING );
> remove_wait_queue ( q , &wait );

Before I go to your questions, I'll first answer that this _is_ buggy
code.  If the condition is checked and you are woken up between the
while (!condition) and the set_current_state, then you will end up
sleeping forever or until someone sends you a signal.

> first:doesnt in the way from checking the !condition to
> set_current_state  the condition can be changed no?

Yes, and then put it again after schedule.

>
> second:why not putting the schedule ( ); right after the
> set_current_state ( ) , what the point in checking the if (
> signal_pending ( ) first, if the proccess doesnt started to sleep yet?

Yes, I would put the signal_pending check after the schedule (as most of
the kernel does this).

> third: in the cleaning in the way from putting the set_current_state (
> TASK_RUNNING ) into remove_wait_queue , cant the queue wait list ( q )
> wake up again the wait procsess?

Yeah, so?  There's no harm in that, except for an extra cpu cycles that
are done to wake it up.  That, I wouldn't change.

> ( thnks for the help , please if it can be done answer quickly i am
> tanker in the idf and need to come back to the army soon , ( no
> internet there... ) )

BTW, this is not an IRC, we use normal capitalization and normal spelling
(when we know how to spell a word ;-).  So the next time you send to the
list, send it as if you were writing a serious letter, or you may just be
ignored. (as you might have been if I didn't respond).

-- Steve

  reply	other threads:[~2005-10-21 13:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-21 11:22 Yitzchak Eidus
2005-10-21 13:03 ` Steven Rostedt [this message]
2005-10-21 13:10   ` Jesper Juhl
2005-10-21 14:41   ` Yitzchak Eidus
2005-10-21 15:07     ` Steven Rostedt
2005-10-21 18:36   ` Lee Revell
2005-10-21 14:00 Nick Warne
2005-10-21 15:56 ` Steven Rostedt

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=Pine.LNX.4.58.0510210848030.3903@localhost.localdomain \
    --to=rostedt@goodmis.org \
    --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

all inboxes | Powered by JetHome®