Course contentsShow
← Computer Science
Lesson 1161 of 2,87227. Pipelining and PerformanceFree lesson

Three Classes of Hazards

Overview of structural, data, and control hazards and their fundamental causes in pipeline execution.

Three Classes of Hazards

What You'll Learn

You'll learn the three fundamental types of hazards that can disrupt smooth pipeline execution and why they occur.

The Three Types of Pipeline Hazards

When instructions flow through a pipeline, they ideally move smoothly from stage to stage like cars on an assembly line. However, certain conditions force the pipeline to stall or work incorrectly. These problems fall into three categories:

1. Structural Hazards

These occur when two instructions need the same hardware resource at the same time. Imagine two cars trying to use the same piece of equipment on an assembly line simultaneously—they can't both fit.

Example: If your processor has only one memory port, and one instruction needs to fetch data from memory while another needs to write to memory in the same clock cycle, you have a conflict.

2. Data Hazards

These happen when an instruction depends on the result of a previous instruction that hasn't completed yet. Think of trying to paint a car before the primer has dried—you need to wait for the earlier step to finish.

Example: If instruction 2 needs to add a value that instruction 1 is still computing, instruction 2 must wait or risk using the wrong value.

3. Control Hazards

These arise from branch instructions that change the program counter. The pipeline doesn't know which instruction to fetch next until the branch resolves. It's like cars on an assembly line not knowing which path to take at a fork in the road.

Example: After a conditional jump instruction, the pipeline may fetch the wrong next instruction if it guesses the branch outcome incorrectly.

Key Takeaway: The three classes of hazards—structural (hardware conflicts), data (instruction dependencies), and control (branching uncertainty)—represent the fundamental challenges that prevent pipelines from achieving ideal performance.