jasonpogi1669

Deadlock Free Condition using C++

Mar 14th, 2022 (edited)
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int get_resource(int process, int need) {
  5.     // suppose there are X processors and N is the maximum needed
  6.     // resources of each processors, then to get the minimum resources,
  7.     // allocate (N - 1) resources on each (X - 1) processors, therefore, the
  8.     // X-th processor will have no resources
  9.    
  10.     // allocate 1 resource that will be used to complete the resources
  11.     // required by every processor, and once the (X - 1)-th processor is
  12.     // done processing, then the maximum value will be allocated for the X-th processor
  13.     int mn = 0;
  14.     mn = process * (need - 1) + 1;
  15.     return mn;
  16. }
  17.  
  18. int main() {
  19.     int process = 3;
  20.     int need = 4;
  21.     cout << "R >= " << get_resource(process, need) << "\n";
  22.     return 0;
  23. }
  24.  
Add Comment
Please, Sign In to add comment