Test and test-and-set: Difference between revisions

Content deleted Content added
Chgros (talk | contribs)
No edit summary
m skip redirect
Line 1:
In [[computer science]], the [[test-and-set]] CPU [[instruction (computer science)|instruction]] is used to implement
[[mutual exclusion]] in [[multiprocessor]] environments. Although a correct [[lock (computer science)|lock]] can be implemented with test-and-set, it can lead to [[memory contention]] in busy lock (caused by bus locking and cache invalidation when test-and-set operation needs to access memory [[atomic (computer science)|atomicatomically]]ally).
 
To lower the overhead a more elaborate locking protocol '''test and test-and-set'''
Line 19:
The entry protocol uses normal memory reads to spin, waiting 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 [[minimalshort-circuit evaluation]], the entry protocol could be implemented as:
 
'''procedure''' EnterCritical() {