Course contentsShow
← Computer Science
Lesson 1325 of 2,87230. Process SynchronizationFree lesson

Banker's Algorithm: Safety Check

Step-by-step process of determining if a resource allocation request leaves the system in a safe state.

Banker's Algorithm: Safety Check

You'll learn the exact procedure for checking whether granting a resource request keeps the system in a safe state.

What Is the Safety Check?

The Banker's Algorithm relies on determining if a resource allocation decision leaves the system in a safe state—meaning every process can eventually finish without deadlock. The safety check is the step-by-step test that proves whether a particular allocation (like granting a request) is safe.

The Step-by-Step Process

When a process requests resources, you simulate granting the request and then run this safety algorithm:

  1. Initialize a work vector (available resources after granting the request) and a finish array (tracking which processes can complete).

  2. Find an unfinished process whose maximum remaining need can be satisfied with current available resources (work).

  3. Simulate that process finishing: Add its currently allocated resources back to work (as if it released them). Mark it as finished.

  4. Repeat step 2-3 until either:

    • All processes are marked finished → Safe state! ✓
    • No process can finish but some remain → Unsafe state! ✗ (potential deadlock)

Think of it like budgeting: you want to ensure that even in the worst case (everyone asks for their maximum need), you can satisfy processes one-by-one until everyone completes.

Why It Matters

Without this check, granting a request might trap you in a state where processes hold resources but can't get enough to finish—classic deadlock. The safety check is your deadlock avoidance guarantee.

Key Takeaway:
The Banker's Algorithm safety check simulates whether all processes can finish by repeatedly finding processes whose needs can be met, "running" them to completion, and reclaiming their resources until all finish successfully.