Jim Donelson wrote: > I'd like to see the code for compare_exchange and the lock function.
compare_exchange is a single architecture-specific instruction; that's what we're discussing. Lock functions are described in Ulrich Drepper's futex paper. > > The purpose of a spin lock is to avoid a more expensive kernel call > > if the mutex is released quickly (or not taken at all). Presumably > > you enter the kernel after n tries and sleep so that you are not > > using up quanta while spinning. > > That doesn't work with a single processor. While you are spinning, > it's impossible for the other thread to release the mutex until you > are preempted, so potential benefit from spinning is marginal and > often outweight by the benefit of not spinning. > > Of course it does - sleeping on a sp means "preempt me now". Yes, but *spinning* on a spinlock does not. You propose spinning n times before sleeping. The mutex will only be released during spin time if you are randomly preempted during that short time. -- Jamie _______________________________________________ uClinux-dev mailing list uClinux-dev@uclinux.org http://mailman.uclinux.org/mailman/listinfo/uclinux-dev This message was resent by uclinux-dev@uclinux.org To unsubscribe see: http://mailman.uclinux.org/mailman/options/uclinux-dev