Sunday, October 2, 2016

rsktutors

Deadlock

Dead Lock
Dear Reader,
        Today morning I was using my computer system for different types of works. I observed my computer system gets hang for sometimes(may be unknown reasons). Based on this issue, I decided to share the information about this Deadlock concept which often comes with Operating system. So let's begin our discussion.
What is a Deadlock?
        Before answering this question, we have to ensure that our computer system has been modeled with limited resources like memory, printers, tape drives, CPU etc. That means the allocated work to a computer system to perform, it has to share some same resources for every work. At that point of time, we may get this deadlock situation.

        So, We can give the understanding meaning for deadlock. Deadlock is the situation where the computer system requesting for one resource, but that one was already utilizing by another process. At the same time, that process needs some resource, which was held by the first process. In this case, no process executes. Every process remains in the waiting state for the infinite time. This situation is known as Deadlock situation. The following simple figure explains this.

In general, a deadlock occurs in concurrent programming, in which two or more operations/processes are waiting to complete the other operation/process. Which leads nothing to complete.
  
How to Avoid Deadlock:

        By following 4 methods, we can prevent the deadlock situation. Because of all these causes deadlock situations.

a. Mutual Exclusion:
        If one process is using a shared data(which may be modifiable), the another process must not do the same operation at the same time. Suppose more than one process is trying to do an operation on the shared data, one process only allowed to this. All the other processes were kept in waiting state, to avoid critical section(trying to access shared resource, must not concurrently access). Once, the execution of the first process has finished, the other process which was under waiting state should permit to use that shared data. This technique is known as Mutual Exclusion.


b. Hold and Wait:
        Processes must release holding resources for simultaneous access by the other processes. I.e., Requesting process hold already, resources while waiting for requested resources.  


c. No Preemption:
          Preemption means temporarily interrupting an operation being carried out by a computer. If it was not allowed, Deadlock occurs. I.e.,  Resources cannot be removed temporarily by a process holding it.
d. Circular Wait:
          The processes in the computer system form a circular list, where each process in the list is waiting for a resource held by the next process in the list.


Ok. But,  How handle a deadlock, if already it occurs? Let us see.

How to handle Deadlock?

a. Preemption:
          By taking a resource, which was already held by a process and allocate it to another requesting process. But, it may lead to other types of problems.
b. Rollback:
          We should make a regular record of system operations at each stage. Suppose, at any situation causing deadlock, immediately roll back everything to the previous stage.    
c. Killing one or more process(s):
        Just terminate one or more process to avoid a deadlock situation. It is simple, but care must be taken.

By using Banker's Algorithm, we can avoid Deadlock situation. Banker's algorithm was developed by  Edsger Dijkstra. According to Banker's algorithm, consider each request as it occurs, and see if granting it leads to a safe state. If it is a safe state, then the request is granted. Otherwise, it is postponed.


With this information, I hope you can understand the Deadlock situation and it's preventing and handling methods. Please share this information. And please feel free to give comments or suggestions in the below section. See you in my next article.
Thank You.



rsktutors

About rsktutors -

RSK is an Associate Professor in Master of Computer Applications, having 15+ years of teaching experience in computer science. He taught and shared his knowledge with more than thousand students, which brings excellent future for them. He is also article writer for various computer books which were using by so many private education institutions. He also developed and deployed a good number of software applications for private educational institutions. You can find RSK on Google+ and Facebook.

Subscribe to this Blog via Email :