COMP 3500 Lecture 29: Mock Exam 2Matlab

Java Python 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?

dai 写COMP 3500 Lecture 29: Mock Exam 2Matlab

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         

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值