[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1ED05FB5-17F7-42B2-BEAA-446F7DADAE46@mac.com>
Date: Mon, 5 Mar 2007 11:30:49 -0500
From: Kyle Moffett <mrmacman_g4@....com>
To: Andrew Morton <akpm@...ux-foundation.org>
Cc: Mathieu Desnoyers <compudj@...gle.com>,
Haavard Skinnemoen <hskinnemoen@...el.com>,
linux-kernel@...r.kernel.org
Subject: Re: Thread flags modified without set_thread_flag() (non atomically)
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
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists