Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Compare-and-swap
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Atomic computer processor instruction}}In [[computer science]], '''compare-and-swap''' ('''CAS''') is an [[atomic (computer science)|atomic]] [[instruction (computer science)|instruction]] used in [[thread (computer science)#Multithreading|multithreading]] to achieve [[synchronization (computer science)|synchronization]]. It compares the contents of a [[memory location]] with a given (the previous) value and, only if they are the same, modifies the contents of that memory location to a new given value. This is done as a single atomic operation. The atomicity guarantees that the new value is calculated based on up-to-date information; if the value had been updated by another thread in the meantime, the write would fail. The result of the operation must indicate whether it performed the substitution; this can be done either with a simple [[Boolean logic|boolean]] response (this variant is often called '''compare-and-set'''), or by returning the value read from the memory location (''not'' the value written to it), thus "swapping" the read and written values.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)