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
Busy waiting
(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!
== Alternatives == Most operating systems and threading libraries provide a variety of [[system call]]s that will [[Process states#Blocked|block]] the process on an event, such as lock acquisition, timer changes, [[I/O]] availability or [[signal (computing)|signals]]. Using such calls generally produces the simplest, most efficient, fair, and [[race condition|race]]-free result. A single call checks, informs the scheduler of the event it is waiting for, inserts a [[memory barrier]] where applicable, and may perform a requested I/O operation before returning. Other processes can use the CPU while the caller is blocked. The scheduler is given the information needed to implement [[priority inheritance]] or other mechanisms to avoid [[Resource starvation|starvation]]. Busy-waiting itself can be made much less wasteful by using a delay function (e.g., <code>[[sleep()]]</code>) found in most operating systems. This puts a thread to sleep for a specified time, during which the thread will waste no CPU time. If the loop is checking something simple then it will spend most of its time asleep and will waste very little CPU time. In programs that never end (such as operating systems), infinite busy waiting can be implemented by using unconditional jumps as shown by this [[Netwide Assembler|NASM]] syntax: <kbd>jmp $</kbd>. The CPU will unconditionally [[JMP (x86 instruction)|jump]] to its [[program counter|own position]] forever. A busy wait like this can be replaced with: <syntaxhighlight lang="asm"> sleep: hlt jmp sleep </syntaxhighlight> For more information, see [[HLT (x86 instruction)]].
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)