Active waiting

This article or section requires a revision. Details are indicated on the discussion side. Please to improve it and removes afterwards this marking helps.

Active waiting or Busy Waiting is a programming techniques around a process (and/or. to let wait a Thread) for occurring a condition. The process runs so long „in the circle “, until the condition is fulfilled. This technology is used particularly for spin LOCKs. An example in pseudo code:

Function warte_bis (parameter condition) {  (not condition) {} // runs so long in the circle to the condition is fulfilled.
}

That has the large disadvantage that the process stresses the full arithmetic performance of the system thereby, again and again the condition to examining, and thus out-brakes different processes. That is above all also unfavorable, because there is the straight other processes, which must ensure that the condition is fulfilled.

The situation becomes somewhat better, if the operating system (and/or. the run time environment) the possibility offers, a process for a given time „sleeps “to leave. This method is called also slow busy waiting or lazy polling. Then the function can be converted in such a way:

Function warte_bis (parameter condition) {  (not condition) {sleep so long (1 second); } // examines the condition once per second }

The disadvantage is however that it is here frequently longer waited would be than necessary (up to one second longer), because the condition is only again examined if „the sleep time ran off “. Also no more is not stressed the full arithmetic performance of the system, because the process most time sleeps „“, but the condition is still unnecessarily often examined.

Active waiting and/or. Busy Waiting is considered generally as very bad programming style and should be used only as all-last possibility. Modern operating systems and/or. Run time environments offer usually LOCKs or monitors , which it permit to examine condition only exactly then again if the variables, on which it depends, changed.

 

  > German to English > de.wikipedia.org (Machine translated into English)