Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3. What is a busy waiting? What is an alternative to busy waiting ?(2 points) 4.

ID: 3805927 • Letter: 3

Question

3. What is a busy waiting? What is an alternative to busy waiting ?(2 points)
4.  What is the distinction between the critical section and the critical data?(2 points)5. Describe the difference between a monitor and a semaphore (2 points).

5. Describe the difference between a monitor and a semaphore (2 points).

6. A file is to be shared among different processes, each of which has a unique id number and a priority levelnumber. The file can be accessed simultaneously by several processes, subject to the following constraint:The process priority number must be greater than or equal to the priority numbers all of the other processesthat are currently accessing the file. Using pseudocode (see below), write a monitor to coordinate access to the file. (6 points)

7. There are three cooperating processes. They all read data from the same input device. Each process, when itgets the input device, must read two consecutive data, only one process may access the input device at a time(Hint: use mutual exclusion to achieve it). Use semaphores to synchronize. Include declaration and initialization.(SEE example on BB – and Video on ) (8 points)

P1:  input (x1, x2)    P2:  input (y1, y2)   P3:  input (z1, z2)C = y1 + z1    B = x1 + z2 + A   A = y2 –x2        ` Print D     D = B + C

         

8. Consider the following snapshot of a system(6 points)R1 has 8 instances, R2 has 10 instances, and R3 has 7 instances
Allocation   Max    Need   Available

  

           Is the system in a safe state? If yes, list an ordered sequence of processes. Show all work.

9. Synchronization barriers are a common paradigm in many parallel applications. A barrier is supposed to block a callingthread until all N threads have reached the barrier. (Parallel applications often divide up the work, e.g. matrix operationsor graphical rendering, among N processes, each of which compute independently, reach an barrier, exchange results,then work on the next phase of computation) Many times the number of threads is not known in advance. Onepseudocode monitor solution is as follows:


Monitor Barrier ( ){ int numThreads ; int numThreadsAtBarrier ;  newThreadCreated( ){  numThreads++; } barrierReached( ){  numThreadsAtBarrier ++;  if(numThreadsAtBarrier == numThreads)   numThreadsAtBarrier = 0;   signalAll( );  else   wait( ); } initilaizationCode( ){  numThreads =0;  numThreadsAtBarrier = 0;

}

}

a. Provide comments in the psuedocode, describing the monitor code (1 points)

b. Briefly describe a difficulty in a semaphore solution to this barrier problem (2 points)

10. How can priority inversion occur? What can be done to prevent priority inversion?(3 points)

Explanation / Answer

3) Busy waiting is the condition when a cpu goes in a loop waiting for the conditions to get true.It spends most of its time in a tight loop waiting for a device to become ready. The alternative to this can be awaitTermination() method.

4) Critical section is a code segment that accesses shared variables and has to be executed as an atomic action. It means that in a group of cooperating processes, at a given point of time, only one process must be executing its critical section. If any other process also wants to execute its critical section, it must wait until the first one finishes whereas critical data is the important and the crucial data which needs to be kept safe from unwanted third parties because leakage of that data may lead to a huge loss of revenue to a particular form.

5) A monitor is a set of routines. These are protected using locks of mutual exclusion. Only a single thread can come and execute within the monitor. The condition for the thread to be allowed to get executed within the onitor is that it must have the lock. A semaphore is little simple than a monitor. Its main purpose is to protect shared resources using a lock. The application which needs the resources must have the lock with it otherwise those resources will not be aloowed to share with that application.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote