From: Kyle Moffett <mrmacman_g4@mac.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Mathieu Desnoyers <compudj@google.com>,
Haavard Skinnemoen <hskinnemoen@atmel.com>,
linux-kernel@vger.kernel.org
Subject: Re: Thread flags modified without set_thread_flag() (non atomically)
Date: Mon, 5 Mar 2007 11:30:49 -0500 [thread overview]
Message-ID: <1ED05FB5-17F7-42B2-BEAA-446F7DADAE46@mac.com> (raw)
In-Reply-To: <20070301144138.57d6d8c7.akpm@linux-foundation.org>
On Mar 01, 2007, at 17:41:38, Andrew Morton wrote:
> Well, it's unusual for code to want to test multiple bitflags in
> the same operation. Perhaps thread_info.flags is unusual in that
> regard.
>
> But one can still do
>
> if (foo->flags & (1<<bar)|(1<<zot))
>
> Which can get to be a pain if it happens in a lot of places. But
> if it only happens in a few places, this seems a reasonable price
> to pay, given the safety gains.
>
> Plus I'm _forever_ having to go into the header file to remember
> whether REQ_RW is the bitmask or the bit offset.
Hey Andrew, I think you just fell victim to an order-of-operations
bug; '&' has a higher priority than '|' does, so:
if ( (foo->flags & (1<<bar)) | (1<<zot))
Or:
if ( dynamic_value | always_true_constant )
And as such this if statement is always true. You'd need an extra
pair of parentheses to make it correct.
Cheers,
Kyle Moffett
next prev parent reply other threads:[~2007-03-05 16:31 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-26 20:10 Mathieu Desnoyers
2007-03-01 6:03 ` Andrew Morton
2007-03-01 6:23 ` David Miller
2007-03-01 8:17 ` Andrew Morton
2007-03-01 9:34 ` Haavard Skinnemoen
2007-03-01 9:45 ` Andrew Morton
2007-03-01 10:14 ` Haavard Skinnemoen
2007-03-01 15:13 ` Haavard Skinnemoen
2007-03-01 19:59 ` Mathieu Desnoyers
2007-03-01 22:41 ` Andrew Morton
2007-03-05 16:30 ` Kyle Moffett [this message]
2007-03-05 14:40 ` Andi Kleen
2007-03-05 22:04 ` Andrew Morton
2007-03-06 4:35 ` Mathieu Desnoyers
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=1ED05FB5-17F7-42B2-BEAA-446F7DADAE46@mac.com \
--to=mrmacman_g4@mac.com \
--cc=akpm@linux-foundation.org \
--cc=compudj@google.com \
--cc=hskinnemoen@atmel.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®