1) How can you implement mutex variables? Please give the pseudo code 2) Suppose
ID: 3669134 • Letter: 1
Question
1) How can you implement mutex variables? Please give the pseudo code
2) Suppose there are four pprocess A, B, C, and Dwhich arrive at 10, 10, 130, 250 msec respectively. The lengths of process A, B, C, and D are 50, 200, 15, and 25 msec, respectively. Ignore the process switching overhead.
A) Compute the average wait time if you are using shortest job first algorithm
B) Compute the average wait time if you are using round robin algorithm, assuming the CPU quanta is 30 ms.
Answer to A (may be incorrect)= ( (50-10) + (250-10) + (265-130) + (515-25)) / 4 = 226.25 ms
Explanation / Answer
In multithreading environment, thread synchronization is very important. mutex is basically used for thread synchronization. In multithreading environment, threads required some shared resources, the access control of these resources is provided by the mutex variables.
Pseudo Code for Mutex Variable showing locking and unlocking
AquireLock(anyCondition i, mutex mtx)
{
acquire_mutex (mtx);
while (LOCKED)
wait (i, mtx);
lock=LOCKED;
mutex_release (mtx);
}
LockReleasing(anyCondition i, mutex mtx)
{
acquire_mutex (mx);
lock = UNLOCKED;
signal (cv);
mutex_release (mx);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.