Skip to content

erickfunier/BankerAlgorithm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Banker Algorithm

This is a version of the banker algorithm which is an algorithm to resource allocation with impass prevention, this version makes a simulation using process created manually and how they are managed.

The project is separated in five packages:
  • domain: related to the business rules

    • BankerObj.java
      Contains the quantity and arrays of processes and available resources, in addiction to the AllocationA, ClaimC and NeedCA (C-A) matrices. The matrices are made with the List of ProcessObj with which we can dinamically add and remove processes.
    • ProcessObj.java
      Used as a process object, it contains an ID and an array of resources, this array is the maximum of resources necessary for the process.
  • port: the ports related to the application

    • Cli.java
      Handle the man-machine-interface to the application
    • FileDataInput.java
      Handle the file data input
  • thread: contains the threads

    • ThreadNewProcess.java
      Insert new processes to the application in runtime execution (6 process with 15 sec interval)
    • ThreadRunBanker.java
      Run the banker algorithm itself. The simulation of a process execution is handled by the Thread.Sleep in 10 sec.
  • usecase: usecases of the application

    • AddProcess.java
      Add the process in runtime, invoked by ThreadNewProcess each 15 sec.
    • CheckSafeState.java
      Check if the system is in SAFE/ UNSAFE state
    • ExecuteBanker.java
      Run the banker algorithm itself
    • LoadProcesses.java
      Load the processes to the system from startFile.txt
  • Main.java
    Run the application starting all classes used by application

Flowcharts

Main - ThreadNewProcess

ThreadRunBanker

CheckSafeState

ExecuteBanker

Execution

Case 1, the best cenario, new process added but keep SAFE:
Input: ______________________________________________________________________________

Input1


Output:


The starterFile generate the following matrix:

Output1

The banker started in SAFE state

Output1.1

As the new processes are add the banker keep running, but updating the sequence of processes

Output1.2

The list of executed process:

Output1.3


Case 2, on this case the system is started in SAFE state but turn to UNSAFE when adding process at runtime:
Input:


Input2


Output:


The starterFile generate the following matrix:

Output2.3

The banker started in SAFE state

Output2.3

After insert P6 the system go to UNSAFE state

Output2.3

After that the system can't exit of the UNSAFE:

Output2.3


Conclusion The algorithm works as expected managing a lot of Deadlocks. But handle new process insertion is a problem, the process already enter allocating some resource, and, with that, the system go to UNSAFE state, in addiction to, the simulation is not considering the execution time of a process, if a process takes a long time all other process need to wait until the end.
Another not considered question is if a process need more resources when it is running, in this case all system will stop. Despite that the banker's algorithm is interesting when it is running on a limited and controlled operational system, with the knowledge of all processes used by the system.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages