CS代考 COMP 3430 Operating Systems

COMP 3430 Operating Systems
Locks and Deadlock
Franklin 2nd, 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)

Deadlock can only happen when all four hold: 1. Mutual exclusion
2. Hold-and-wait
3. No preemption
4. Circular wait
© CC BY-NC 2.0

Mutual exclusion
Threads claim exclusive control of re- sources they require (e.g., a thread grabs a lock).
Mutexes (Pixabay License)

Hold-and-wait
Threads hold resources allocated to them (e.g., locks that they have al- ready acquired) while waiting for addi- tional resources (e.g., locks that they wish to acquire).
This is mine. (Pixabay License)

No preemption
Resources (e.g., locks) cannot be forcibly removed from threads that are holding them.
Give it to me! (Pixabay License)

Circular wait
There exists a circular chain of threads such that each thread holds one or more resources (e.g., locks) that are being requested by the next thread in the chain.

Let’s look at some code and decide if it can or cannot deadlock. Download code.c from the course web page.

Teams: What does this code do?

Managing locks in the code.
▶ Course-grained or fine-grained?
▶ How do threads acquire the locks?
▶ 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.

▶ 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