Question

In: Computer Science

In a scenario where several threads are contending for a critical section there are 3 options...

  1. In a scenario where several threads are contending for a critical section there are 3 options for threads that fail to acquire the lock i) spin; ii) yield and iii) placed in a wait queue. Discuss the pros and cons of the 3 approaches.

Solutions

Expert Solution

1. Spin method

Pros

● suitable for use in interrupt context

● avoids indefinite sleep/wait of a thread as it keeps the thread active in a light loop

● very fast as no time is taken to put a thread in wait queue and again moving the thread to the ready queue

● low power consumption as moving task to wait queue and moving task to ready queue is a tiring process

Cons

● it must not be used in uniprocessor system as it can create deadlock

spin method is not recursive

● spin lock need to be taken special care when it is used between interrupt handler and thread as it may cause deadlock

2. Yield

Yield temporarily pause the execution of current thread and let other threads to execute

Pros

● it lets the scheduler to choose any thread according to the priority of threads

● current process will continue execution if all the other process waiting in the queue are of lower priority

● if current thread is taking very long to execute, it gives chance for other threads waiting for long time hence reducing indefinite wait or starvation problem

Cons

●yield is a slow approach

● more context switches are there in yield as compared to spin

3. Place thread in a wait queue

In this synchronization approach, the scheduler puts the thread in sleep condition or move it to the wait queue(FIFO) . Semaphore is used for this approach

Pros

●it is a very simple approach

● most suitable for process context

● semaphore lets processes to be preempted

Cons

● increase CPU overhead as putting a task in wait queue and then invoking it again is long time consuming process.

● it is not flexible in terms of modifying the priority of threads as the thread put in wait queue first will move to ready state first

● slowest approch for synchronization


Related Solutions

As described in Section 4.5.2, Linux does not distinguish between processes and threads. Instead, Linux treats...
As described in Section 4.5.2, Linux does not distinguish between processes and threads. Instead, Linux treats both in the same way, allowing a task to be more akin to a process or a thread depending on the set of flags passed to the clone() system call. However, many operating systems — such as Windows XP and Solaris — treat processes and threads differently. Typically, such systems use a notation wherein the data structure for a process contains pointers to the...
3. Describe a scenario where the Spearman correlation would be appropriate to use in calculating the...
3. Describe a scenario where the Spearman correlation would be appropriate to use in calculating the strength of the relationship between two variables. Identify the variables and explain the rationale for your answer. What makes this scenario different from the scenario in the previous question?
. Is the following software solution to the critical section problem correct?                      {          &nbsp
. Is the following software solution to the critical section problem correct?                      {              int   lock = 0;                ………….                if (lock == 0) then lock = 1                 else                         while (lock == 1) no-op;                   enter_CS;                          CS                    exit_CS;                 ……….             }
Find the critical depth, critical slope and Froude Number at section y=0.9 m in a 0.55...
Find the critical depth, critical slope and Froude Number at section y=0.9 m in a 0.55 m wide, m=1 trapezoidal channel carrying water at the rate of 0.95 m3/s. n=0.016.
3. Describe a scenario where driving a bridge circuit with a constant cur- rent source is...
3. Describe a scenario where driving a bridge circuit with a constant cur- rent source is more advantageous than driving the circuit with a constant voltage source.
write C program to create 4 threads for summing the numbers between 1 and 40 where...
write C program to create 4 threads for summing the numbers between 1 and 40 where the first thread computes the sum between 1 and 10; the second thread computes the sum between 11 and 20; the third thread computes the sum between 21 and 30; and the fourth thread compute the sum between 31 and 40. The output should be similar to the following. The sum from 1 to 10 = 55 The sum from 11 to 20 =...
Write a C++ program where you implement a synchronized multithreaded version of HAPPY with four threads....
Write a C++ program where you implement a synchronized multithreaded version of HAPPY with four threads. The program will take in an array from 1 to n (n = 50) and will be passed to four different threads: If the current number is divisible by 2, then print HAP If the current number is divisible by 5, then print PY If the current number is divisible by both 2 and 5, then print HAPPY If the number is neither divisible...
Case 3 Antiock Hardware: An Inventory Case Study This case study presents a scenario where an...
Case 3 Antiock Hardware: An Inventory Case Study This case study presents a scenario where an error in the inventory valuation, that may prove to be significant, was found by the external auditor of a large wholesale hardware distributor during the course of their audit. Since the objective of all audit clients is to obtain an unqualified opinion, the case focuses on the ability of the client to correct the error to the extent possible and the procedures the external...
C Programming language problem I need to write a program which uses several threads (like 8...
C Programming language problem I need to write a program which uses several threads (like 8 threads for example) to sum up a number. The following program is using 1 thread but I need several threads to compile it. There was a hint saying that using multiple separate for loop and combining them will make a multi-threaded program. #include <stdio.h> #include <stdlib.h> #include <pthread.h> int sum; // this data is shared by the threads void *runner(void *param); // threads call...
Critical Thinking Activities Read each clinical scenario and discuss the questions with your classmates. Scenario A...
Critical Thinking Activities Read each clinical scenario and discuss the questions with your classmates. Scenario A As a student, you have several tasks to complete. There is an Anatomy and Physiology test in 4 days. You just collected the library materials you need for a comprehensive paper due in 1 week. A 50-page reading assignment needs to be completed for a lecture the day after tomorrow. 1. How would you organize to accomplish these tasks? 2. In what order of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT