Operating System Fundamentals 26
State Machines Without the need to switch
from one process to the next, the creation of an operating system is significantly reduced. In fact, many embedded systems that have no multitasking often do not include an operating system for cost reasons. If we consider the act of attempting to read a text message while we are driving, we know that the driver will only take their eyes off the road when the traffic appears to be under control. The driver will then quickly look at some of the text on the mobile phone and then return to looking at the road. This process will continue as long as there are text messages to be read or places to drive to. If we draw a small diagram showing these two actions we have something like this
Mobile
Road looks okay
We heard a horn/screeching tires or we looked
at the mobile long enoughRoad
Figure 3.1 Example of a simple state machine This diagram shows that we start off by watching the road and when we feel that the road conditions look okay (no cars or pedestrians) we then look at the mobile phone. We then read the message on the mobile phone until
one of two things occurs 1. We hear something that needs our attention such as some screeching tire or we notice something in our peripheral vision.
2. We have been looking at the mobile phone for sometime and realize that we should probably see if we are about to hit something. Figure 3.1 (above) is used in many computer design documents and is called a
state machine. The circles represent the state of the machine and the arrows represent actions that cause us to change from one state to another. In
the case of our texting driver, there are two states looking at the road, or looking at the mobile. Although it maybe possible to hold the phone in such away that the peripheral vision
encounters most of the road, it remains a fact that you cannot actually look at both the phone and the road at the same time. Regardless of the opinion of texting while driving, a single core CPU can only perform one instruction at a time which is the whole reason for describing this analogy. The important thing to takeaway from this analogy is that somethings in life are modeled really well by state machines and that events can cause some resources to change from one state to the next.
Operating System Fundamentals
27
Share with your friends: