On Nov 3, 8:07 pm, Ro <
rohitgirm...@gmail.com> wrote:
> Is the spinlock a performance advantage or is there some other
> reason ?
It's not really a spin lock. A spin lock tries to do the same thing
over and over until it succeeds. The thin-lock code wants to work
without interruption, so it's using an atomic compare-and-swap
operation. If the "old" value isn't what the code expects, it means
some other thread has come through and modified the state, so the code
needs to start over. If, when starting over, it discovers that the
lock has "fattened", it uses a different call path.
Thin locking has performance benefits over "fat" locking, since it can
be implemented as an inline atomic operation rather than a call to the
pthread library (which will, at a minimum, perform the same atomic
operation).