Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the advantages and disadvantages of Busy-waiting and timer interrupts in programming? [closed]

A feasible way to achieve a suitable time delay is to use busy-waiting, however what are the advantages and disadvantages of using a busy-waiting or timer interrupts approach programming?

like image 588
M.Khalaf Avatar asked Oct 30 '25 11:10

M.Khalaf


2 Answers

There are probably many, I will try to address what seems most important to me.

Advantages of busy-waiting:

  • The execution flow is usually easier to comprehend and thus less error prone.
  • Timing can be determined more accurately in some cases

Disadvantages:

  • No other code (except perhaps other interrupt routines) can be executed.
  • CPU-time is wasted: If no other work must be processed it is still more efficient to set some powersaving-state and let a timer interrupt wake it up in time.
like image 165
Ctx Avatar answered Nov 01 '25 02:11

Ctx


A disadvantage of busy-waiting in embedded devices is the increased power consumption. In a busy wait, the processor is running full-blast, consuming power with no result. Most low power processors have the ability to put the processor to sleep while waiting for a timer interrupt, reducing power consumption dramatically. Lower power consumption = longer battery life.

like image 44
AShelly Avatar answered Nov 01 '25 02:11

AShelly