Re: [patch 1/4] prepare_to_wait/finish_wait sleep/wakeup API

Linus Torvalds (torvalds@transmeta.com)
Wed, 25 Sep 2002 21:37:23 -0700 (PDT)


On Wed, 25 Sep 2002, David S. Miller wrote:
>
> I don't want to say that your changes cannot be made to work,
> but it's been one of my understandings all these years that
> the fact that the task itself controls it's presence on the
> wait queue is what allows many races to be handled properly and
> cleanly.

No, the important part is that the process adds itself and marks itself as
sleeping _before_ doing the test. The "marks itself as sleeping" part is
the really important one.

The "removes itself" was/is really just a matter of being able to handle
loops more efficiently (which is probably a case of optimizing for the
wrong thing, since the common case is to wait for just _one_ event,
especially since we made the herd behaviour go away with the exclusive
stuff).

The "removes itself" thing was also something I thought was cleaner (have
the same entity do both add and remove), but I certainly buy into the CPU
lock bouncing arguments against it, so..

> For example, the ordering of the test and add/remove from
> the wait queue is pretty important.

The test and add yes. Remove no, since remove is always done after we know
we're waking up.

Linus

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/