THINK FIRST·CODE LATER

← All labs

Deadlock detection with multiple instances

Problem

Implement the detection algorithm.

Input: n m; Available; n rows of Allocation; n rows of Request (current outstanding requests).

  • Processes whose allocation is all zeros are finished from the start (they do not appear in the completion list).
  • Repeat passes over P0…Pn−1: take, in index order, every unfinished process whose Request ≤ Work, and add its Allocation to Work.

Print Can complete (in order): P0 P2 P3 P4 P1 (or none), then No deadlock or DEADLOCK: P1 P2 P3 P4 (the unfinished processes, in index order).

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.