Test and test-and-set: Difference between revisions

Content deleted Content added
No edit summary
BWDuncan (talk | contribs)
m Repairing link to disambiguation page - You can help!
Line 3:
 
To lower the overhead a more elaborate locking protocol ''Test and Test-and-set''
is used. The main idea is '''not''' to [[Busy waiting|spin]] in [[test-and-set]] but increase the likelihood of successful [[test-and-set]] by using following entry protocol to the lock:
 
''boolean'' locked := false ''// shared lock variable''
Line 17:
}
 
The entry protocol uses normal memory reads to [[spin]], and waitwaiting for the lock to become free. [[Test-and-set]] is only used to try to get the lock when normal memory read says its free. Thus the expensive atomic memory operations happens less often than in simple spin around [[Test-and-set]].
 
If the [[programming language]] used supports [[Lazy evaluation#Minimal evaluation|minimal evaluation]], the entry protocol could be implemented as: