DEADLOCKS:
In concurrent computing, a deadlock is a state in which each member of a group waits for another member, including itself, to take action, such as sending a message or more commonly releasing a lock
In an operating system, a deadlock occurs when a process or thread enters a waiting state because a requested system resource is held by another waiting process, which in turn is waiting for another resource held by another waiting process. If a process is unable to change its state indefinitely because the resources requested by it are being used by another waiting process, then the system is said to be in a deadlock
Deadlock Avoidance:
If we have prior knowledge of how resources will be requested, it's possible to determine if we are entering an "unsafe" state.
Possible states are:
Deadlock:
No forward progress can be made.
Unsafe state:
A state that may allow deadlock.
Safe state:
A state is safe if a sequence of processes exist such that there are enough resources for the first to finish, and as each finishes and releases its resources there are enough for the next to finish
Deadlock Prevention:
Mutual exclusion:
Automatically holds for printers and other non-sharable.
b) Shared entities (read only files) don't need mutual exclusion (and aren’t susceptible to deadlock.)
c) Prevention not possible, since some devices are intrinsically non-sharable
Hold and wait:
a) Collect all resources before execution.
b) A particular resource can only be requested when no others are being held. A sequence of resources is always collected beginning with the same one.
c) Utilization is low, starvation possible
No preemption:
a) Release any resource already being held if the process can't get an additional resource.
b) Allow preemption - if a needed resource is held by another process, which is also waiting on some resource, steal it. Otherwise wait
Circular wait:
a) Number resources and only request in ascending order.
b) EACH of these prevention techniques may cause a decrease in utilization and/or resources. For this reason, prevention isn't necessarily the best technique.
c) Prevention is generally the easiest to implement.
thanks
@haidermehdi @hassanabid
@event-horizon@vvarishayy