I want to improve the performance of a program by replacing some of the mutexes with spinlocks. I have found a spinlock implementation in
which I intend to reuse. I believe this implementation is safer than simpler implementations in which threads keep trying forever like the one found here
But i need to clarify some things on the yield function found here
First of all I can assume that the numbers 4,16,32 are arbitrary. I actually tested some other values and I have found that I got best performance in my case by using other values.
But can someone explain the reasoning behind the yield code. Specifically why do we need all three
BOOST_SMT_PAUSE
sched_yield
andnanosleep