Em Mon, Oct 20, 2008 at 03:34:07PM -0700, david@xxxxxxx escreveu:I've seen a lot of discussion about how sched_yield is abused by
applications. I'm working with a developer on one application that looks
like it's falling into this same trap (mutexes between threads and using
sched_yield (or more precisely pthread_yield()) to let other threads get
the lock)
however I've been having a hard time tracking down the appropriate
discussions to forward on to the developer (both for why what he's doing
is bad, and for what he should be doing instead)
could someone point out appropriate mailing list threads, or other
documentation for this?
http://kerneltrap.org/Linux/Using_sched_yield_Improperly
> > One example I know of is a defragmenter for a multi-threaded memory > > allocator, and it has to lock whole pools. When it releases these > > locks, it calls yield before re-acquiring them to go back to work. > > The idea is to "go to the back of the line" if any threads are > > blocking on those mutexes.
> at a quick glance this seems broken too - but if you show the specific > code i might be able to point out the breakage in detail. (One > underlying problem here appears to be fairness: a quick unlock/lock > sequence may starve out other threads. yield wont solve that > fundamental problem either, and it will introduce random latencies > into apps using this memory allocator.)
You are assuming that random latencies are necessarily bad. Random latencies may be significantly better than predictable high latency.