I did, and cannot give you a concrete answer about how many times to
spin. It depends on a lot of factors. Think about adaptive backoffs.
This can be used in the spin portion of an adaptive mutex.
Actually, one time I wrote a program that measured the number of spins
vs the number of lock acquires vs the number of kernel waits. They were
generally different, on different systems. Heck, they were different on
the same system under various periods of load. I remember having
different ways to measure lock acquires. Was the lock obtained during a
spin? Was the lock obtained after going to kernel land? Iirc my old code
was getting some output like:
[0]: thread[0] lock_acquired after 13 spins
[1]: thread[1] lock_acquired after 128 spins and 1 kernel wait
[2]: thread[0] lock_acquired after 3 spins
[3]: thread[1] lock_acquired after 0 spins
Another factor that can impact the "optimal" spin count is the
complexity of the critical section itself. Adaptive locks tend to
"shine" when the critical section is really short and sweet, so to
speak... ;^)