COMP 3430 Operating Systems
Franklin 4th, 2022
Copyright By PowCoder代写 加微信 powcoder
By the end of today’s lecture, you should be able to:
▶ Identify concurrency bugs in a program (both non-deadlock and deadlock).
▶ Describe how to change code to prevent deadlock from happening.
The Rocket Book (Public Domain)
Term test 1
▶ Test next Friday (March 11th, 2022)
▶ On Crowdmark, during class time.
▶ Zoom meeting/e-mail for questions
(Zoom has priority).
▶ All are upload images (screenshots/photos).
▶ Material: Up to and including week 5.
▶ No programming questions.
Let’s look at some code and decide if it can or cannot deadlock.
© CC BY-NC 2.0
Managing locks in the code.
▶ Coarse-grained or fine-grained?
▶ How do threads acquire the locks?
▶ Specifically: What order are the locks acquired in?
Take 5 minutes to discuss these questions about the locks. I’ll ask you to share your findings when you come back, so please make sure you’re writing down what you’re thinking.
Deadlock can only happen when all four hold:
1. Mutual exclusion 2. Hold-and-wait
3. No preemption 4. Circular wait
▶ Can this code deadlock if executed concurrently?
▶ How does each condition for deadlock hold?
Deadlock can only happen when all four hold:
1. Mutual exclusion 2. Hold-and-wait
3. No preemption 4. Circular wait
How would you change this code to break a condition of deadlock?
Breaking deadlock
▶ Lock in the transfer object. (doesn’t work )
▶ File-scope lock. (breaks hold-and-wait/circular wait
(serializes all transfers )
▶ Sort accounts. (works!
▶ pthread_mutext_trylock. (breaks hold-and-wait
lead to livelock )
) (complicated )
▶ Multithreading and locks are buggy business.
▶ Deadlock is an uncommon, but difficult to fix bug caused by
▶ Breaking one condition for deadlock prevents deadlock.
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com