COMPUTER SYSTEMS&MOD MSGT/ET SA AC PKG
3rd Edition
ISBN: 9780134671123
Author: Bryant
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 12, Problem 12.29HW
Program Plan Intro
Deadlocks:
- The deadlock denotes a situation where a collection of threads remains blocked.
- It denotes waiting for a condition that will 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 some execution trajectory reaches deadlock state “d” then no further progress is 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.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Const N = 50;
Var Tally: integer;
Procedure Total;
Var Count:integer;
Begin
For Count := 1 to N
do Tally := Tally + 1
End;
End;
Begin (* main
program *)
Tally := 0;
Parabegin
Total; Total;
Paraend;
Write (Tally)
End.
Compose a thread
safe pseudocode
version that
guarantees the upper
and lower bound of
the shared variable
Tally are the same
value after execution.
// please don't copy from chegg
in java:
Use multithreading and thread synchronization to code an application simulating a bank deposit and withdrawal process. Set up an account containing an initial balance of $1000.00 for both of the two shared threads, Husband and Wife. When a thread makes a deposit in an account, the other thread must wait. If the account balance is $0.00, no withdrawals are permitted. Assume a deposit transaction requires 0.2 seconds to complete and a withdrawal transaction requires 0.5 seconds to complete. Generate random number 1 as deposit and 2 as withdrawal, respectively. Write a driver class MultiThreadAppt o test your application, repeat, and display the operations 50 times. Document all source code as required above.
In 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…
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
Similar questions
- For programming tasks, we can use an Array or an Array List. Describe when using an Array would be a good choice, and Describe when using an Array List would be a better choice. You must start a thread before you can read and reply to other threadsarrow_forward#include <pthread.h>#include <stdio.h>#include <unistd.h>#include <stdlib.h> int count = 0; void *threadfunc(void *arg){ cout<<"Thread Complete\n"; count++; return NULL; } int main(){ count = 0; pthread_t A,B,C;pthread_create(&A, NULL, threadfunc, NULL); pthread_create(&B, NULL, threadfunc, NULL); pthread_create(&C, NULL, threadfunc, NULL); while(count<50) {pthread_join(A, NULL); if(count<50) pthread_join(B, NULL); if(count<50) pthread_join(C, NULL); } return 0; } What is wrong?arrow_forwardQUESTION 8: Practical (a) Cold Code Provide Java source code for the following problem. You can assume that all relevant packages have been imported. Provide a class called PrintMessage that is a task that can be run on a Thread. The constructor of PrintMessage sets the message to be displayed and repeat value, a number that represents the number of times the message must be displayed. When PrintMessage is started it prints the message to System.out then waits 200ms, this process is repeated based on the repeat value. Provide a Main class that instantiates a PrintMessage with appropriate values, loads the instance onto a Thread and starts it.arrow_forward
- The program shown in Figure 4.22 uses the Pthreads API. What would be the output from the program at LINE C and LINE P? #include #include int value = 0; void *runner(void *param); /* the thread */ int main(int argc, char *argv []) pid_t pid; pthread_t tid; pthread attr_t attr; pid = fork(); if (pid == 0) { /* child process */ pthread_attr.init(&attr); pthread_create (&tid,&attr,runner,NULL); pthread_join(tid,NULL); printf("CHILD: value = %d",value); /* LINE C */ else if (pid > 0) { /* parent process */ wait (NULL); printf("PARENT: value = %d",value); /* LINE P */ } void *runner(void *param) { value - 5; pthread_exit(0); Figure 4.22 C program for Exercise 4.19.arrow_forwardJAVA PROGRAMMING You are required to create a main class to apply ExecuterService with SingleThreadExecuter. The variable i is integer number and MUST be input from the keyboard. Output should be like this: Please input i: 3 pool-1-thread-1: 1 pool-3-thread-1: 1 pool-3-thread-1: 2 pool-3-thread-1: 3 pool-2-thread-1: 1 pool-2-thread-1: 2 pool-2-thread-1: 3 pool-1-thread-1: 2 pool-1-thread-1: 3 Total = 9Below is the part of code.class Counter public class Counter { private int counter; public void increment(){ counter++; } public void decrement(){ counter--; } synchronized public void myIncrement(){ counter++; } synchronized public void myDecrement(){ counter--; } }arrow_forwardIn this assignment, you are provided with working code that does the following: 1. You input a sentence (containing no more than 50 characters). 2. The program will read the sentence and put it into an array of characters. 3. Then, it creates one thread for each character in the sentence. 4. The goal of the program is to capitalize each letter that has an odd index. The given program actually does this, but lacks the synchronization of the threads, so the output is not correct. You will need to provide the synchronization using mutex locks. Specifically, you are to (1) declare the mutex lock, (2) initialize the mutex lock, (3) lock and unlock the mutex lock at an appropriate location that results in the code working as expected, and (4) destroy the mutex lock. Be sure to place the mutex locks so that your program works correctly every time. Do not remove code or functions – you are to add the synchronization pieces only. When compiling using the GNU C compiler, be sure to include the…arrow_forward
- Purpose of this assignment: To allow student to be able to implement a Java thread-based application by loading allowing user to perform a computation operation. Instruction: This is an individual assignment. You have to use Java thread to write a program that can perform two calculation functions concurrently. One of the function will generate a series of Fibonacci number sequence. The second function will calculate the result of factiorial function. This factorial function will allow the user to input a start number, end number and number of threads. Then, function will split into thread to perform the calculation. At the end, the function will merge the result of each thread calculation and display the result.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_forwardCan you please help me with this code because I am struggling on how to do this, This has to be in C code. question that I need help with: Write a multithreaded program that calculates various statistical values for a list of numbers. This program will be passed a series of numbers on the command line and will then create three separate worker threads. One thread will determine the average of the numbers, the second will determine the maximum value, and the third will determine the minimum value. For example, suppose your program is passed the integers 90 81 78 95 79 72 85 The program will report The average value is 82 The minimum value is 72 The maximum value is 95 The variables representing the average, minimum, and maximum values will be stored globally. The worker threads will set these values, and the parent thread will output the values once the workers have exited. (We could obviously expand this program by creating additional threads that determine other statistical values,…arrow_forwardCould you kindly utilize solely my code as I contributed to its development? I emphasize, please utilize only my code. This code has to be in C code and I have provided part of code below. Question that I need help with: You need to use the pthread for matrix multiplication. Each thread from the threadpool should be responsible for computing only a partof the multiplication (partial product as shown in the above picture –all Ti(S) are called a partical product). Your main thread should splitthe matrices accordingly and create the partial data arrays that areneeded to compute each Ti. You must create a unique task with thedata and submit it to the job queue. You can compute the partialproducts concurrently as long as you have threads available in thethreadpool. You have to remove the task the from queue and submitto a thread in the threadpool. You should define the number ofthreads to be 5 and keep it dynamic so that we can test the samecode with a higher or lower number of…arrow_forwardComputer Science Using Java Write a program that opens up 2 threads of the same class. The threads say "I'm a thread".arrow_forwardWrite java code to create a thread by (extending), theprogram create 3 thread that displaying “fatmah” and thenumber of thread that is running.Rewrite the above program by implementing the RunnableInterfacearrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education