Test and test-and-set: Difference between revisions

Content deleted Content added
Znok (talk | contribs)
m editorial
#suggestededit-add-desc 1.0
Tags: Mobile edit Mobile app edit Android app edit
 
(3 intermediate revisions by 2 users not shown)
Line 1:
{{Short description|CPU Instruction}}
In [[computer architecture]], the [[test-and-set]] CPU [[instruction (computer science)|instruction]] (or instruction sequence) is designed to implement
[[mutual exclusion]] in [[multiprocessor]] environments. Although a correct [[lock (computer science)|lock]] can be implemented with test-and-set, the ''test and test-and-set'' optimization lowers [[resource contention]] caused by bus locking, resp.especially [[cache coherence | cache coherency protocol]] overhead on contended locks.
 
Given a lock:
Line 32 ⟶ 33:
 
==Caveat==
Although this [[Optimization (computer science)|optimization]] is useful in [[system programming]], test-and-set is to be avoided in high-level [[concurrent programming]]: spinning in applications derivesdeprives the operating system scheduler
the knowledge of who is blocking on what. Consequently, the scheduler will have to guess on how to allocate CPU time among the threads -- typically just allowing the threads to use up their timing quota. Threads will end up burningspinning CPU cycles spinningunproductively, waiting for threads that are not scheduled.
 
By using operating-system provided lock objects, such as mutexes, the OS can schedule exactly the unblocked threads.