Professional Documents
Culture Documents
Busy Waiting Means That A Process Is Waiting For A Condition To Be Satisfied in A
Busy Waiting Means That A Process Is Waiting For A Condition To Be Satisfied in A
Busy Waiting Means That A Process Is Waiting For A Condition To Be Satisfied in A
1. What is the meaning of the term busy waiting? What other kinds of waiting are there
in an operating system? Can busy waiting be avoided altogether? Explain your answer.
Busy waiting means that a process is waiting for a condition to be satisfied in a
tight loop without relinquish the processor. Alternatively, a process could wait by
relinquishing the processor, and block on a condition and wait to be awakened at
some appropriate time in the future. Busy waiting can be avoided but incurs the
overhead associated with putting a process to sleep and having to wake it up when
the appropriate program state is reached.
A monitor is used to control access to state variables and condition variables. The
chopsticks themselves are not part of the monitor (nor is the rice). If they were, then
the entire act of eating would have to be a monitor procedure and only one
philosopher could eat at a time. Monitor procedures are defined for the actions of
obtaining the chopsticks and putting them down. These are used as entry and exit
protocols for program segments which actually use the chopsticks; this use takes
place outside the monitor.
A philosopher who wants to eat checks the state of both neighbors and proceeds if
neither is eating. Otherwise the philosopher waits. A philosopher who has finished
eating gives each neighbor a chance to eat, if they are hungry and if their other
chopstick is free.
MONITOR:
DATA:
condition can_eat[NUM_PHILS];
enum states {THINKING, HUNGRY, EATING} state[NUM_PHILS-1];
int index;
INITIALIZATION:
PHILOSOPHER:
/* find out our id, then repeat forever */
me = get_my_id();
while (TRUE) {
/* think, wait, eat, do it all again ... */
think();
pickup(me);
eat();
putdown(me);
}
3. The banker's algorithm is being run in a system with m resource classes and n
processes. In the limit of large m and n, the number of operations that must be
performed to check a state for safety is proportional to m anb. What are the values of a
and b?
Comparing a row in the matrix to the vector of available resources takes m
operations. This step must be repeated on the order of n times to find a process that
can finish and be marked as done. Thus, marking a process takes on the order of mn
steps. Repeating the algorithm for all n processes means that the number of steps is
then mn2.
4. Compare the circular-wait scheme with the deadlock-avoidance schemes (like the
banker’s algorithm) with respect to the following issues:
a. Runtime overheads
b. System throughput
A deadlock-avoidance scheme tends to increase the runtime overheads due to the
cost of keep track of the current resource allocation. However, a deadlock-avoidance
scheme allows for more concurrent use of resources than schemes that statically
prevent the formation of deadlock. In that sense, a deadlock-avoidance scheme
could increase system throughput.
c. If a request from process P1 arrives for (0,4,2,0), can the request be granted
immediately?
Yes it can. This results in the value of Available being (1, 1, 0, 0).One ordering
of processes that can finish is P0, P2, P3, P1, and P4.
For each of the following scheduling algorithms, draw four Gantt charts and determine
the average waiting time.
a. SJF (preemptive)
b. Priority (Non-preemptive) (Priority - P0: 1, P1: 2, P2: 3)
c. RR (Quantum = 5)
d. Multi-level queue (Priority - P0: 1, P1 & P2: 0), SJF (preemptive) with priority 0,
FCFS with priority 1, Fixed Priority Queue & Preemptive