Professional Documents
Culture Documents
Assignment 3: Submitted by Muneeb Shahid Roll No 19011598-138 Section SE-4C Submitted To MR Shahzaib Abbas
Assignment 3: Submitted by Muneeb Shahid Roll No 19011598-138 Section SE-4C Submitted To MR Shahzaib Abbas
Submitted By
Muneeb Shahid
Roll No
19011598-138
Section
SE-4C
Submitted To
Mr Shahzaib Abbas
QUESTION # 04
Deadlock is a line between safe and unsafe state.
it needs, is held by some other process which is also waiting for some other
resource to be released
A state is safe if the system can allocate resources to each process (up to its
maximum) in some order and
each the resource requests that can still make can be satisfied by the
currently available resources
In this situation, if the resources that needs are not immediately available,
then can wait until
When they have finished, can obtain all of its needed resources, complete
its designated task, return its
are deadlocks
QUESTION # 05
Concurrent programs are well known for containing errors that are difficult
to detect,
when more than one thread tries to access the same resource
simultaneously there is a
One is to have threads set checkpoints. For example, if you have a thread
that has a work loop,
you set a timer at the beginning of doing work that's set for longer than you
think the work could
possibly take. If the timer _res, you assume the thread is deadlocked. When
the work is done, you
what other resources a thread might hold. This can directly detect an
attempt to acquire one lock
while holding another one when other threads have acquired those locks in
the opposite order. This
can even detect deadlock risk without the deadlock actually occurring. If
one thread acquires lock
application to check each blocking lock for a possible deadlock and knowing
what to do if it
happens, the only thing you can do after a deadlock is tear the application
down. You can't release
Sometimes you deliberately write code that you know can deadlock and
specifically code it to
avoid the problem. For example, if you know lots of threads take lock A and
then try to acquire
lock B, and some other thread needs to do the reverse, you can code it do a
non-blocking attempt
Typically, it's more useful to spend your effort making deadlocks impossible
rather than making
Benefits of Multithreading:
QUESTION # 06
How monitor helps to solve synchronization problems.
monitor DiningPhilosophers
state[i] = HUNGRY;
test(i);
state[i] = THINKING;
test((i + 4) % 5);
test((i + 1) % 5);}
(state[(i + 1) % 5] != EATING) ) {
state[i] = EATING ;
self[i].signal () ;}}
initialization_code() {
state[i] = THINKING;}}
DiningPhilosophers.pickup(i);
EAT
DiningPhilosophers.putdown(i);
No deadlock
QUESTION # 07
System Model
Mutual exclusion
Hold and wait
No preemption
Circular wait
Deadlock with Mutex Locks
Resource-Allocation Graph
Deadlock Prevention
Deadlock Avoidance
Safe State
Unsafe State
Deadlock State
Banker’s Algorithm
Safety Algorithm
Deadlock Detection
Wait-for Graph
Detection Algorithm
Process Termination
Resource Preemption