Consider a program with five concurrent threads that modify a shared integer variable and use a mutex lock for synchronization. Can a circular wait condition occur in this scenario? If so, why? If not, why not?
Added by Harry L.
Step 1
Circular wait is one of the necessary conditions for a deadlock to occur, where a set of processes are each waiting for a resource held by the next process in the set, forming a circular chain. Show more…
Show all steps
Your feedback will help us improve your experience
Haricharan Gupta and 76 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Is it possible to have a deadlock involving only one single-threaded process? Explain your answer
Haricharan G.
5. Give an example in pseudo-code of 3 processes that use semaphores such that, according to the order in which they are executed, can either: terminate normally; or deadlock. Remember to indicate how the semaphores are initialized. 6. Insert semaphores to satisfy the properties: P1: print(A); print(B); print(C); P2: print(E); print(F); print(G); * print A before printing F * print F before printing C Don't forget to indicate the initial value of the semaphores. 7. Insert semaphores such that only ACERO or ACREO is printed. P1: print(C); print(E); P2: print(A); print(R); print(O); Don't forget to indicate the initial value of the semaphores. 8. Assuming semaphores SA, SB, and SC are initialized at 0, what strings can be printed? P1: repeat print(A); SC.V; SA.P; forever P2: repeat print(B); SC.V; SB.P; forever P3: repeat SC.P; SC.P; print(C); SA.V; SB.V; forever 9. Explain why interrupts are not appropriate for implementing synchronization primitives in multiprocessor systems. 10. 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. 11. Consider the version of the dining-philosophers problem in which the chopsticks are placed at the center of the table and any two of them can be used by a philosopher. Assume that requests for chopsticks are made one at a time. Describe a simple rule for determining whether a particular request can be satisfied without causing deadlock given the current allocation of chopsticks to philosophers.
Akash M.
[20/20/20/20] <5.5> The spin lock is the simplest synchronization mechanism possible on most commercial shared-memory machines. This spin lock relies on the exchange primitive to atomically load the old value and store a new value. The lock routine performs the exchange operation repeatedly until it finds the lock unlocked (i.e., the returned value is 0). addi x2, x0, #1 lockit: EXCH x2, 0(x1) bnez x2, lockit The lock is released simply by storing a 0 into x2. As discussed in Section 5.5, the more optimized spin lock employs cache coherence and uses a load to check the lock, allowing it to spin with a shared var- iable in the cache. lockit: ld x2, 0(x1) bnez x2, lockit addi x2, x0, #1 EXCH x2, 0(x1) bnez x2, lockit Assume that processor cores C0, C1, and C3 are all trying to acquire a lock at address 0xAC00 (i.e., register R1 holds the value 0xAC00). Assume the cache con- tents from Figure 5.37 and the timing parameters from Implementation 1 in Figure 5.38. For simplicity, assume the critical sections are 1000 cycles long. a. [20] <5.5> Using the simple spin lock, determine approximately how many memory stall cycles each processor incurs before acquiring the lock. b. [20] <5.5> Using the optimized spin lock, determine approximately how many memory stall cycles each processor incurs before acquiring the lock. c. [20] <5.5> Using the simple spin lock, approximately how many memory accesses occur? d. [20] <5.5> Using the optimized spin lock, approximately how many memory accesses occur?
Adi S.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD