Hardware Reference
In-Depth Information
loop()
loop2()
loop3()
Execution time
Figure 19-1: Execution of threads
This has led to some complicated situations; Microsoft Windows 3.1 used some-
thing called cooperative multitasking, where applications had to cooperate. If an
application didn't cooperate (either it wasn't designed to run in Windows or crashed)
then control was never given to other applications. In Figure 19-2, the thread
badloop() takes control but never gives it back, leaving two threads unable to
function.
loop()
loop2()
badloop()
Figure 19-2: Noncooperative thread
Today, operating systems use multiple techniques to ensure that applications
will run together, even if one is greedy with system resources, and the entire
system keeps on going even if an application crashes.
While writing this topic, I am using a text editor. In the background is a
music player to help me concentrate. I am using a two-monitor setup, and on
the opposite screen I have a web browser for reference, and the Arduino IDE
to write the sketches that I will be using. If I need a break, I'll play a game, but
I won't close any applications, I'll let the operating system keep them alive
while I have a break. When I've had a break, I'll come back to my text editor
and continue where I was.
Arduino Multitasking
Arduinos, by default, do not multitask. Take this simple sketch as an example:
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
}
 
Search WWH ::




Custom Search