Operating Systems / Chapter 5: Parallel Processes /

Starvation

Starvation is another example where threads or processes are stuck waiting forever to run. But starvation occurs in a different environment than deadlocks. Deadlocks happen due to threads fighting over some resource (such as locks). Starvation happens because the OS will not let processes run for some reason. For example, it is common for the OS to give each process a priority. Then the higher priority processes will run first before the lower priority process. If the OS is not careful, there is a chance that the lower priority processes will never run.

Also, some processes need to run periodically, such as video players. Suppose that the player is trying to play a 30 FPS (frames per second) video. This means that every 1/30 second, the OS should give the player some time to draw an image on the screen. Let's say that it takes the player 1/300 second to draw an image. Then the computer has 9/300 second to let other processes run before giving the player another 1/300 second. Thus, the video player is taking 10% of the computers time.

Now suppose we start playing 11 videos simultaneously on a single computer. The OS lets the players run, and each player runs for 1/30 second. After 10 players run, the first player needs to run again, but the 11th player also needs to run. Suppose that the OS lets the first player run. Then the 11th player must wait. After the first player is finished, the second player needs to run again. The OS may continue to make the 11th player wait, leading to starvation.

Perhaps this is unfair. But if the OS let's the 11th player run, then the other 10 players won't be able to play at 30 FPS. This will result in videos slowing or stuttering. This may be acceptable, or the user may decide to stick to 10 videos or less.

Quiz (1 point)

Suppose that the computer needs 5 milliseconds to draw each player in a videogame. If we want the computer to maintain 30 FPS, then how many players can play the game at a time? Please ignore all other processing times.

Become a subscriber to save your progress, see the correct answer, and more!
Previous Lesson Next Lesson

Comments

Please log in to add comments