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
Test-and-set
(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!
=== Assembly implementation === <syntaxhighlight lang="nasm"> enter_region: ; A "jump to" tag; function entry point. tsl reg, flag ; Test and Set Lock; flag is the ; shared variable; it is copied ; into the register reg and flag ; then atomically set to 1. cmp reg, #0 ; Was flag zero on entry_region? jnz enter_region ; Jump to enter_region if ; reg is non-zero; i.e., ; flag was non-zero on entry. ret ; Exit; i.e., flag was zero on ; entry. If we get here, tsl ; will have set it non-zero; thus, ; we have claimed the resource ; associated with flag. leave_region: move flag, #0 ; store 0 in flag ret ; return to caller </syntaxhighlight> Here <code>tsl</code> is an atomic instruction and <code>flag</code> is the lock variable. The process doesn't return unless it acquires the lock.
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)