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
Infinite loop
(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!
==Intended vs unintended looping== Looping is repeating a set of instructions until a specific condition is met. An infinite loop occurs when the condition will never be met due to some inherent characteristic of the loop. ===Intentional looping=== There are a few situations when this is desired behavior. For example, the games on cartridge-based game consoles typically have no exit condition in their main loop, as there is no operating system for the program to exit to; the loop runs until the console is powered off. Modern interactive computers require that the computer constantly be monitoring for user input or device activity, so at some fundamental level there is an infinite processing [[idle loop]] that must continue until the device is turned off or reset. In the [[Apollo Guidance Computer]], for example, this outer loop was contained in the Exec program,<ref>{{cite web |url=http://klabs.org/history/history_docs/mit_docs/1711.pdf |title=The History of Apollo On-board Guidance, Navigation, and Control |author=David Hoag |date=September 1976 |publisher=Charles Stark Draper Laboratory |access-date=2020-01-23 |archive-date=2016-11-05 |archive-url=https://web.archive.org/web/20161105060425/http://klabs.org/history/history_docs/mit_docs/1711.pdf |url-status=live }}</ref> and if the computer had absolutely no other work to do, it would loop run a dummy job that would simply turn off the "computer activity" indicator light. Modern computers also typically do not halt the processor or motherboard circuit-driving clocks when they crash. Instead they fall back to an error condition displaying messages to the operator (such as the [[blue screen of death]]), and enter an infinite loop waiting for the user to either respond to a prompt to continue, or reset the device. ==== Spinlocks ==== [[Spinlock|Spinlocks]] are low-level synchronization mechanisms used in concurrent programming to protect shared resources. Unlike traditional locks that put a thread to sleep when it can't acquire the lock, spinlocks repeatedly "spin" in an infinite loop until the lock becomes available. This intentional infinite looping is a deliberate design choice aimed at minimizing the time a thread spends waiting for the lock and avoiding the overhead of higher level synchronisation mechanisms such as [[Lock (computer science)|mutexes]]. ====Multi-threading==== In multi-threaded programs some threads can be executing inside infinite loops without causing the entire program to be stuck in an infinite loop. If the main thread exits, all threads of the process are forcefully stopped, thus all execution ends and the process/program terminates. The threads inside the infinite loops can perform "housekeeping" tasks or they can be in a blocked state waiting for input (from socket/queue) and resume execution every time input is received. ===Unintentional looping=== [[File:Infinite loop BSOD.jpg|thumb|A [[blue screen of death]] on [[Windows XP]]. "The [[device driver]] got stuck in an infinite loop."]] Most often, the term is used for those situations when this is not the intended result; that is, when this is a [[software bug|bug]].<ref>{{cite web |url=https://nyxcrossword.com/2013/10/1013-13-new-york-times-crossword.html |title=New York Times Crossword Answers |quote=computing .. a defect .. which .. to loop |date=October 13, 2013 |access-date=January 22, 2020 |archive-date=August 2, 2020 |archive-url=https://web.archive.org/web/20200802040416/https://nyxcrossword.com/2013/10/1013-13-new-york-times-crossword.html |url-status=live }}</ref> Such errors are most common by novice programmers, but can be made by experienced programmers also, because their causes can be quite subtle. One common cause, for example, is that a programmer intends to iterate over sequence of nodes in a [[data structure]] such as a [[linked list]] or [[Tree (data structure)|tree]], executing the loop code once for each node. Improperly formed links can create a ''reference loop'' in the data structure, where one node links to another that occurs earlier in the sequence. This makes part of the data structure into a [[Ring (data structure)|ring]], causing naive code to loop forever. While most infinite loops can be found by close inspection of the code, there is no general method to determine whether a given program will ever halt or will run forever; this is the [[undecidable problem|undecidability]] of the [[halting problem]].<ref>{{cite web|url=https://www.geeksforgeeks.org/halting-problem-in-theory-of-computation|title=Halting Problem in Theory of Computation|date=3 October 2018|access-date=22 January 2020|archive-date=9 August 2020|archive-url=https://web.archive.org/web/20200809100104/https://www.geeksforgeeks.org/halting-problem-in-theory-of-computation/|url-status=live}}</ref>
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)