Re: Thread flags modified without set_thread_flag() (non atomically)

Kyle Moffett
2007-03-05T16:31:36Z

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