COMPUTER SYSTEMS&MOD MSGT/ET SA AC PKG
3rd Edition
ISBN: 9780134671123
Author: Bryant
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 12, Problem 12.30HW
A.
Program Plan Intro
Deadlocks:
- The deadlock denotes a situation where a collection of threads remains blocked.
- It denotes waiting for a condition that would never be true.
- The progress graph denotes invaluable tool for understanding deadlock.
- If “P” and “V” operations are been ordered incorrectly, the forbidden regions for two semaphores would overlap.
- If any execution trajectory reaches deadlock state “d” then no further progress will be possible.
- In this case each thread waits for the other one for a “V” operation that never occurs.
- The overlapping forbidden regions would induce a set of states called “deadlock region”.
- The deadlock is inevitable is trajectory touches a state in deadlock region.
- Once it enters deadlock regions, the trajectories could never leave.
Mutex lock ordering rule:
- A program is deadlock-free if each thread acquires its mutexes in order.
- It releases them in reverse order and given a total ordering for all mutexes.
- The mutex should be achieved in order to ensure deadlock free scheme.
B.
Program Plan Intro
Deadlocks:
- The deadlock denotes a situation where a collection of threads remains blocked.
- It denotes waiting for a condition that would never be true.
- The progress graph denotes invaluable tool for understanding deadlock.
- If “P” and “V” operations are been ordered incorrectly, the forbidden regions for two semaphores would overlap.
- If any execution trajectory reaches deadlock state “d” then no further progress will be possible.
- In this case each thread waits for the other one for a “V” operation that never occurs.
- The overlapping forbidden regions would induce a set of states called “deadlock region”.
- The deadlock is inevitable is trajectory touches a state in deadlock region.
- Once it enters deadlock regions, the trajectories could never leave.
Mutex lock ordering rule:
- A program is deadlock-free if each thread acquires its mutexes in order.
- It releases them in reverse order and given a total ordering for all mutexes.
- The mutex should be achieved in order to ensure deadlock free scheme.
C.
Program Plan Intro
Deadlocks:
- The deadlock denotes a situation where a collection of threads remains blocked.
- It denotes waiting for a condition that would never be true.
- The progress graph denotes invaluable tool for understanding deadlock.
- If “P” and “V” operations are been ordered incorrectly, forbidden regions for two semaphores would overlap.
- If any execution trajectory reaches deadlock state “d” then no further progress will be possible.
- In this case each thread waits for the other one for a “V” operation that never occurs.
- The forbidden regions that are overlapping would induce a set of states called “deadlock region”.
- The deadlock is inevitable is trajectory touches a state in deadlock region.
- Once it enters deadlock regions, the trajectories could never leave.
Mutex lock ordering rule:
- A program is deadlock-free if each thread acquires its mutexes in order.
- It releases them in reverse order and given a total ordering for all mutexes.
- The mutex should be achieved in order to ensure deadlock free scheme.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Q1
THREAD -"C LANGUAGE" ONLY
Write a program that uses 5 threads. Initialize a shared variable with a value of 0.
Each thread must add its Thread ID (tid) to the shared variable.
Once a thread has done the addition, print the ID of the thread.
It is important to make use of mutexes so that only one thread is incrementing the shared variable at a time.
Output the value of the shared variable once all threads have finished incrementing it.
The following question is related to Threading
Task-1:
Write a c program that creates 5 threads and prints which thread is running and after the thread is closed, a new thread starts its execution. Each thread should run sequentially one by one.
OUTPUT:
thread-1 running
thread-1 closed
thread-2 running
thread-2 closed
Chapter 12 Solutions
COMPUTER SYSTEMS&MOD MSGT/ET SA AC PKG
Ch. 12.1 - Prob. 12.1PPCh. 12.1 - Prob. 12.2PPCh. 12.2 - Practice Problem 12.3 (solution page 1036) In...Ch. 12.2 - Practice Problem 12.4 (solution page 1036) In the...Ch. 12.4 - Prob. 12.5PPCh. 12.4 - Prob. 12.6PPCh. 12.5 - Prob. 12.7PPCh. 12.5 - Prob. 12.8PPCh. 12.5 - Prob. 12.9PPCh. 12.5 - Prob. 12.10PP
Ch. 12.6 - Prob. 12.11PPCh. 12.7 - Prob. 12.12PPCh. 12.7 - Prob. 12.13PPCh. 12.7 - Prob. 12.14PPCh. 12.7 - Prob. 12.15PPCh. 12 - Prob. 12.20HWCh. 12 - Derive a solution to the second readers-writers...Ch. 12 - Prob. 12.22HWCh. 12 - Prob. 12.23HWCh. 12 - Prob. 12.24HWCh. 12 - Prob. 12.25HWCh. 12 - Prob. 12.26HWCh. 12 - Some network programming texts suggest the...Ch. 12 - Prob. 12.28HWCh. 12 - Prob. 12.29HWCh. 12 - Prob. 12.30HWCh. 12 - Implement a version of the standard I/O fgets...Ch. 12 - Prob. 12.32HWCh. 12 - Prob. 12.33HWCh. 12 - Prob. 12.34HWCh. 12 - Prob. 12.35HWCh. 12 - Prob. 12.36HWCh. 12 - Prob. 12.37HWCh. 12 - Prob. 12.38HWCh. 12 - Prob. 12.39HW
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Implement a solution to the critical section problem with threads using semaphores. you must add a third counting thread which counts by 1 each time it enters its critical section to 3,000,000. Each counts to 3,000,000 for a total of 9,000,000.arrow_forwardLab 4 Directions Write a C program called threadcircuit to run on ocelot which will provide a multithreaded solution to the circuit-satisfiability problem which will compute for what combinations of input values will the circuit output the value 1. This is the sequential solution, which is also attached. You should create 6 threads and divide the 65,536 test cases among them. For example, if p=6, each thread would be responsible for roughly 65,536/6 number of iterations (if it's not divisible, some threads can end up with one more iteration than the others). The test cases must be allocated in a cyclic fashion one by one. #include <stdio.h>#include <sys/time.h>/* Return 1 if 'i'th bit of 'n' is 1; 0 otherwise */#define EXTRACT_BIT(n,i) ((n&(1<<i))?1:0)int check_circuit (int z) { int v[16]; /* Each element is a bit of z */ int i; for (i = 0; i < 16; i++) v[i] = EXTRACT_BIT(z,i); if ((v[0] || v[1]) && (!v[1] || !v[3]) && (v[2] || v[3])…arrow_forwardDesign a food ordering system where your python program will run two threads, Place Order: This thread will be placing an order and inserting that into a queue. This thread places new order every 0.5 second. (hint: use time.sleep(0.5) function) Serve Order: This thread will serve the order. All you need to do is pop the order out of the queue and print it. This thread serves an order every 2 seconds. Also start this thread 1 second after place order thread is started. Pass following list as an argument to place order thread, orders = ['pizza','samosa','pasta','biryani','burger'] This problem is a producer,consumer problem where place_order thread is producing orders whereas serve_order thread is consuming the food orders. Use Queue class.arrow_forward
- Subject Name: Advanced Object-Oriented Programming 1. Complete the below given code (1) class NyThread Thread t: Runnable ( MyThread (String n, int pl t (2) (3) : / creates teh Thread t with nane n : // changen the priority to p Syster.out.printin ("Thread "+n+* created with priority "+p): t. (4) : // exexcute the thread t. I // The only abatarct aethed in Runnable public for (int 1=10: 1>=1: 1--) { Syaten.out.prántin ("Thread *t.getName ()+"\e i - "a) : (5) try { (6) :/ ma ke the Thead t eleep to 2 seconds } catch (Exception e) Syater.out.printin ("Exception in Child"): System.out.printin ("Thread "+t. getName ()+" 1s Exiting"): public statie void main (Stringt) arga) { MyThread t1, 12; ti - new MyThread ("R1", 7): t2 = new MyThread ("R1", 3): try ( :// 2 atatements to aake the Threads ti a v2 exit at same time (8) ) catoh (Exception e) ( Syster.out.printin("Exception in main"): System.out.printin ("Thread Main is Exiting"): 1. 2. 3. 4. 6. 7. 8. 5.arrow_forwardIn C++ This exercise involves implementing the solution to the bounded buffer/readers and writers problem using threads. You will create a program that accepts four command line arguments: run_time (the length of time the program should run) buffer_size (number of slots in the bounded buffer) num_producers (number of producer threads) num_consumers (number of consumer threads) The program will create a thread for each producer and consumer. As each thread produces or consumes a data item, it will print its status. Example Output Here are some sample runs: Not enough arguments If not enough arguments are provided, the program should print an error message and exit. $ ./bounded_buffer Wrong number of arguments. Usage: bounded_buffer <run_time> <buffer_size> <num_producers> <num_consumers> $ Invalid argument If an argument is less than or equal to 0, the program should print a message and exit $ ./bounded_buffer 10 5 1 0 ./bounded_buffer 10 5 1 0 num_consumers…arrow_forwardWrite a c program that creates 5 threads and prints which thread is running and after the thread is closed, a new thread starts its execution. Each thread should run sequentially one by one. OUTPUT: thread-1 running thread-1 closed thread-2 running thread-2 closedarrow_forward
- 1arrow_forwardWhen loops are used, do you agree that utilizing threading for loops will reduce the time it takes for the loop to execute?arrow_forwardIf we add a semaphore shared between P1 and P2 and change the pseudocode to the following one. What will be the final value of s? const int n=10; int s; // shared variable between two processes (threads) semaphore m=1; void P1( ) { int i=0; for (i=0;iarrow_forwardMust attach output screenshot apply a proper thread synchronization technique #include #include using namespace std; int result = 0; void add1() { for(int i=0; iarrow_forwardPlease sample solution Not complicatedarrow_forwardIn Python code: Put the thread_function on a thread. Put 3 threads into a queue and run the threads. import queuequeue = queue.Queue def thread_function(name): print("Thread %s: starting", name) time.sleep(2) print("Thread %s: finishing", name) # start threads by passing function to Thread constructorfrom pprint import pprintimport threadingimport time def threadfunc(*t): print(">>>>",*t) time.sleep(1) print('[',*t,']') time.sleep(2) print("<<<<",*t) arg1 = ("AAAAAAAA")threadA = threading.Thread(target=threadfunc,args=arg1)threadA.start() arg2 = ("BBBBBBBB")threadB = threading.Thread(target=threadfunc,args=arg2)threadB.start() arg3 = ("CCCCCCCC")threadC = threading.Thread(target=threadfunc,args=arg3)threadC.start() threadA.join()threadB.join()threadC.join() # multiple threadsimport threadingimport time tnames = ('AAAAAAAA','BBBBBBBB','CCCCCCCC')count = len(tnames)threadlist = []count = 3 def threadfunc(*t):…arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
Recommended textbooks for you
- Systems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning