COMP 3500 Lecture 29: Mock Exam 2
Exercise 1 (Menti): When several processes access the same data concurrently and the outcome of the execution depends on the particular order in which the access takes place, is called critical condition.
Exercise 2 (Menti): A condition variable is basically a container of threads that are waiting for a certain condition.
Exercise 3 (Menti): Deadlock will arise if a process holding at least one resource is waiting to acquire additional resources held by other processes.
Exercise 4 (Menti): If a resource allocation graph contains no cycles, then there is no deadlock.
Exercise 5 (Menti): We can prevent the circular wait condition by
A) using a safe sequence
B) using mutual exclusion
C) defining a linear ordering of resource types
D) all of the mentioned
Exercise 6 (Menti): The terms “deadlock prevention” and “deadlock avoidance” can be used interchangeably.
Exercise 7 (Menti): Like semaphores, each condition variable is maintaining a counter to keep track of conditions.
Exercise 8 (Menti): In ____ mode, the kernel runs on behalf of the user.
A) user B) kernel C) hybrid D) all the above
Exercise 9 (Menti): System calls provide an essential interface between a process and hardware components.
Exercise 10 (Menti): Which one of the following ways periodically test for deadlocks?
A) Prevention B) Avoidance C) Detection D) Deletion
Exercise 11: There are three processes accessing four resources labeled from R1 to R5. Please use a resource allocation graph to detect if there is a possible deadlock. In case of a deadlock, can you change the order of the lock operators in a process to prevent the deadlock?
void P1() { while (true) { lock(R2); lock(R1); lock(R3); /*Critical region*/ unlock(R2); unlock(R1); unlock(R3); } } |
void P2() { while (true) { lock(R5); lock(R3); lock(R4); /*Critical region*/ unlock (R5); unlock (R3); unlock (R4); } } |
void P3() { while (true) { lock(R4); lock(R1); /*Critical region*/ unlock (R4); unlock (R1); } } |
Exercise 12.1: An operating system (OS) is managing one resource type containing 174 instances. There are 37 current processes sharing these instances coordinated by the OS. Each process must access 6 instances. Will a potential deadlock occur? Please justify your answer.
Exercise 12.2: An operating system (OS) is managing one resource type containing 413 instances. There are 100 current processes sharing these instances coordinated by the OS. Each process must access 5 instances. Is this a deadlock-free scenario? Please justify your answer.
Exercise 13: The Cigarette Smoker's Problem. There are three smokers and one cigarette dealer. A smoker must make a cigarette before he or she can smoke it. Making a cigarette requires (1) tobacco, (2) paper, and (3) matches. Each smoker has one of the three items. Specifically, one smoker has tobacco, another has paper, and a third one has matches. The cigarette dealer has an infinite supply of tobacco, paper, and matches. The dealer randomly selects two of the three items and places them on a table. Then, the smoker who has the third item makes a cigarette and smoke. After the first smoker finishes smoking, the dealer will place other two of the three items on the table so that another smoker can enjoy cigarettes. Please use semaphores to synchronize the three smokers and the dealer.
版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。