Question

Following is the hardware TestAndSet solution for critical-section problem. Can this solution sat...

Following is the hardware TestAndSet solution for critical-section problem. Can this solution satisfy bounded waiting? Explain your answer.

Shared boolean variable: lock (initialized to false)

Solution:

while (true) {

while(TestAndSet(&lock))

; /*do nothing

//critical section

lock = FALSE;

//remainder section

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

TestAndSet is a hardware solution to the synchronization problem. In TestAndSet, we have a shared lock variable which can take either of the two values, 0 or 1.

0 Unlock
1 Lock

Before entering into the critical section, a process inquires about the lock. If it is locked, it keeps on waiting until it becomes free and if it is not locked, it takes the lock and executes the critical section.

In TestAndSet, Mutual exclusion and bounded waiting can be preserved. For Example:-

you have n processes, process i is currently executing, when it enters the critical section, it sets its waiting to false.

Now, what happens when process i has finished ? Process i will look for an index j (process j) that is waiting to run in the critical section. In other words, we are looking for a process that is waiting to enter the critical section that is different from the current process that ran in a critical section

Process 1    Process 2

wants to set target to TRUE

target is changed to TRUE

the result comes back to FALSE so no busy waiting

wants to set target to TRUE

it receives the result TRUE

busy waits as long as Process 1 is in the critical section

leaves critical section

sets target to FALSE

Add a comment
Know the answer?
Add Answer to:
Following is the hardware TestAndSet solution for critical-section problem. Can this solution sat...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • a)Given the following solution for the critical section problem for two processes (the code shown is for processes Pi),...

    a)Given the following solution for the critical section problem for two processes (the code shown is for processes Pi), show why it does not satisfy the mutual exclusion requirement. Here,lock is a shared variable initialized to FALSE. (Hint: Indicate one scenario where the mutual exclusion requirement is violated.) do {            lock = FALSE;           while (lock);           lock = TRUE         Critical section           /Empty section                   Remainder section } (b)Does this satisfy the progress requirement? Justify your answer

  • a. Given the solution for the critical section problem for two processes (the code shown is...

    a. Given the solution for the critical section problem for two processes (the code shown is for processes Pi), show why it does not satisfy the mutual exclusion requirement. Here, lock is a shared variable initialized to FALSE. (Hint: Indicate one scenario where the mutual exclusion requirement is violated.): do { while (lock); lock=TRUE Critical section lock=FALSE; Remainder section } b. What happens if lock is initialized to TRUE in the code above?

  • The following code fragment is a 2-process "solution" to the critical section problem try ] =...

    The following code fragment is a 2-process "solution" to the critical section problem try [i] = true ; while (incs[j]) no-op; while (turn=j and try[j]) no-op; incs [i] = true ; critical section try [i] = false; incs [i] = false; turn = j ; Does the above "solution" meet all 3 conditions of critical sections? Please explain your answer.

  • Considering the following algorithm, which of the following requirements are satisfied? Considering the following algorithm, which...

    Considering the following algorithm, which of the following requirements are satisfied? Considering the following algorithm, which of the following requirements are satisfied? int currentThread = 1; bool thread1 Access = true; bool thread2Access = true; thread1 { thread2 { While (true) { While (true) { while(thread2Access == true) { while(thread1Access == true) { If (currentThread == 2) { If (currentThread == 1) { thread1 Access = false; thread2Access = false; While (currentThread == 2); While (currentThread == 1); thread1 Access...

  • Given two processes, the structure of each process is as follows: do f flag [i] -ture...

    Given two processes, the structure of each process is as follows: do f flag [i] -ture ; while (flag [j] “ turn-j); //Critical Section flag[i]false; //Remainder Section while (1) Determine whether it is a correct solution to the critical-section problem. If yes, prove that the algorithm satisfies requirements for the critical-section problem. If' not, explain your answer

  • What are the three requirements for a solution to the critical-section problem? Consider the following solution...

    What are the three requirements for a solution to the critical-section problem? Consider the following solution to the dining-philosophers' problem. // Global variables. Shared among threads int state [5]; semaphore mutex; I/ Initially set to 1 semaphore s [5] I Initially s[i] is set to 0 for all i Initially statei]-THINKING for all i void philosopher (int i) f int left(int i) f // Philosopher to the left of i // % is the mod operator. while(TRUE) thinkO take.forks ()...

  • TRUE-FALSE     Basic synchronization principles and multithreading 1. Java user threads can implement both busy-waiting and no-busy-waiting...

    TRUE-FALSE     Basic synchronization principles and multithreading 1. Java user threads can implement both busy-waiting and no-busy-waiting policy. 2. Priority inversion avoids deadlocks. 3. Spinlock mutex can be used as an adaptive mutex. 4. Java RTE can be blocked for Input/Output operation. 5. Interrupted user thread, which executes a method in a monitor, must be rolled back to undo any changes it performed. 6. The synchronization primitive by disabling interrupts can be used by an application program. 7. Bounded-waiting requirement is...

  • pleasw answer as soon as possible . this is for my exam practice . please read...

    pleasw answer as soon as possible . this is for my exam practice . please read the code and answer the question In a system, there are multiple reader processes which read from a shared file and multiple writer processes which update a shared file. The following variables are shared among all processes: int readCounter; semaphore mutex, writeLock; Reader and writer processes are given in the following C++-like pseudo programs: Reader Process // Non-Critical Section P(mutex); Writer Process // Non-Critical...

  • I undertand the algo is Peterson's Solution and that it will not cause deadlocks or busy waiting. But does this so...

    I undertand the algo is Peterson's Solution and that it will not cause deadlocks or busy waiting. But does this solve the critical section problem in its entirety such as in the case of more than 2 processes. Does this Scanned Documents 1.jpg w the following code. What algorithm does this implement? solve the critical section problem, defend your decision, explain in detail Revi #define FALSE O #define TRUE 1 /*number of processes / #define N 2 int turn int...

  • Can you help me to answer 1, 2 and 3. EXERCISES FOR SECTION 2.5 1. For...

    Can you help me to answer 1, 2 and 3. EXERCISES FOR SECTION 2.5 1. For each of the following statements, determine whether it is true or false and justify your answer. a. Every bounded set is closed. b. Every closed set is bounded. c. Every closed set is compact. d. Every bounded set is compact. e. A subset of a compact set is also compact. 2. For each of the following statements, determine whether it is true or false...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT