On 18 December 2017 at 18:17, Ed Jaffe <[email protected]> wrote: > On 12/18/2017 2:45 PM, [email protected] wrote: >> >> In the code fragment above why is the LT (Load and Test) instruction >> necessary ? >> What was the author trying to accomplish after Compare and Swap ? > > > This is a spin lock, not a suspend lock.
Indeed. And presumably the author is trying to make the spin cause less of a performance hit on other CPUs and caches (*this* CPU will be in a hard loop regardless) by using LT instead of CS to do the spinning. CS performs an expensive serialization function seen by all CPUs and even the channel subsystem. LT is, I think, subject only to block-concurrency considerations. I wouldn't want to have to argue the case for having an enabled application program do spin loops. But we don't know the context this code was found in; maybe it's part of an OS or a standalone program. Tony H.
