Concept explainers
A.
Explanation of Solution
Explanation:
The above diagram describes about th...
B.
Deadlock:
In a computer system, a set of blocked processes each holding a resource and waiting to acquire the resource held by another process in the set is called a deadlock problem.
Example:
Consider the savings and loan institution. In that, the savers want to withdraw the amount from their own accounts than the available amount in the institution.
- At the same time, the institution cannot force the borrowers to return the amount they borrowed from the institution.
- Now, the deadlock problem occurs in this scenario because the borrowers hold the resource (amount) that the institution has to satisfy the request of the savers.
- This deadlock problem can be resolved by arranging the required amount by the institution for the valuable customer from the other institutions.
C.
Deadlock:
In a computer system, a set of blocked processes each holding a resource and waiting to acquire the resource held by another process in the set is called a deadlock problem.
Example:
Consider the savings and loan institution. In that, the savers want to withdraw the amount from their own accounts than the available amount in the institution.
- At the same time, the institution cannot force the borrowers to return the amount they borrowed from the institution.
- Now, the deadlock problem occurs in this scenario because the borrowers hold the resource (amount) that the institution has to satisfy the request of the savers.
- This deadlock problem can be resolved by arranging the required amount by the institution for the valuable customer from the other institutions.
D.
Explanation of Solution
Explanation:
The above diagram describes about the progr...
Want to see the full answer?
Check out a sample textbook solutionChapter 12 Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
- : In the famous dining philosophers problem, a bunch of philosophers aresitting around a circular table with one chopstick between each of them. A philosopher needs bothchopsticks to eat, and always picks up the left chopstick before the right one. A deadlock couldpotentially occur if all the philosophers reached for the left chopstick atthe same time. Using threadsand locks, implement a simulation of the dining philosophers problem that prevents deadlocksarrow_forwardDefine a class MyData that holds an instance variable x, a function to increment x by 5, and a getter to return the value of x. In a MyUtil class, define an aggregate relationship where MyUtil holds a MyData reference. MyUtil should extend Thread and provide an implementation for run that contains a for loop that iterates 100000 times calling the increment function of the myData reference. Define the main method in MyUtil that creates the instance of MyData. Define a data collection for storing MyUtil objects. In three separate for loops, (1) create and add five instances of MyUtil to the data collection previously defined. (2) Call the start function on each thread. (3) Ensure each thread completes before main completes. Print out the value of x from myData. In a brief comment, describe what is happening when you execute the program several times. Also in the comment, what keyword could be used where to prevent the issue seen?arrow_forwardWrite a program that has a counter as a global variable. Spawn 10 threads in theprogram, and let each thread increment the counter 1000 times in a loop. Print the finalvalue of the counter after all the threads finish—the expected value of the counter is10000. Run this program first without using locking across threads and observe theincorrect updating of the counter due to race conditions (the final value will be slightly lessthan 10000). Next, use locks when accessing the shared counter and verify that the counteris now updated correctlyarrow_forward
- What is the safe sequence? [Note, try to exexute the threads sequentitally that is T0, then T1 and so on. If T2 gets first chance in safe sequence, then again start with T0, then T1 and so on. ] [Hints. input safe sequence without any space or anything in between such as - T4T2T0T1T3]arrow_forwardIn this program, you manipulate a Table, having an array of doubles, which is shared between 3 threads DepositThread and 3 other threads RemoveThread. - DepositThread increments (by 1) the values of the array.- RemoveThread decrements (by 1) the values of the array.- Every DepositThread and RemoveThread has a thread name.- Before starting the incrementing or decrementing task, every thread has to introduce itself by printing a sentence as follows: THREAD thread-name is incrementing/decrementing the array... Example: "THREAD DepositTh-1 is incrementing the array..." - The table is initially filled by zeros. So, logically, at the end of threads’ job, the table values must be all zeros again. - The main thread waits till all other threads finish execution, and then it prints the resulting array elements.- Class Table is given below: Table - tab[] : double + Table()+ incTab() : void+ decTab() : void+ displayTab() : void Using java language with…arrow_forwardWrite a program that launches 1,000 threads. Each threadadds 1 to a variable sum that initially is 0. You need to pass sum by reference toeach thread. In order to pass it by reference, define an Integer wrapper object tohold sum. Run the program with and without synchronization to see its effect.arrow_forward
- We said that only one method may be active in each given JVM thread. Why do you think so?arrow_forwardIs it even feasible to have a deadlock if there is just one process that is using a single thread? Please elaborate on your response.arrow_forwardI have my code below and I am stuck at the last part which is the display of the thread that finished first and last. There are times when it give the correct output and sometimes it is not. How can it be fixed? The sample output is given below and the output I made. import java.util.Random;import java.util.Scanner; class prog1 implements Runnable { private String cName = new String(""); private int x; public int c1 = 0, c2 = 0, c3 = 0; // static array to store which thread closed first public static int [] order = new int[3]; // index of array private static int index = 0; public prog1 (String cName, int x){ this.cName = cName; this.x = x; } @Override public void run(){ Random r = new Random(); int randNum; for (int i = 1; i <= this.x; i++){ randNum = r.nextInt(x) + 1; if(i == this.x) { // put the number // get number from name's last character of thread…arrow_forward
- Write a program that creates a certain number of sellerthreads thatattempt to sell all the available tickets. There is a global variablenumTickets which tracks the number of tickets remaining to sell.We will create many threads that all will attempt to sell tickets untilthey are all gone. Each thread will exit after all the tickets havebeen sold.E.g. if we have 4 tickets and 2 sellerthreads then output should be likeSeller #1 sold one (3 left)Seller #0 sold one (2 left)Seller #1 sold one (1 left)Seller #0 sold one (0 left)Seller #1 noticed all tickets sold! (I sold 2myself)Seller #0 noticed all tickets sold! (I sold 2myself)Done Do this using semaphores and c++ linux basedarrow_forwardWrite a program that creates a certain number of sellerthreads thatattempt to sell all the available tickets. There is a global variablenumTickets which tracks the number of tickets remaining to sell.We will create many threads that all will attempt to sell tickets untilthey are all gone. Each thread will exit after all the tickets havebeen sold.E.g. if we have 4 tickets and 2 sellerthreads then output should be likeSeller #1 sold one (3 left)Seller #0 sold one (2 left)Seller #1 sold one (1 left)Seller #0 sold one (0 left)Seller #1 noticed all tickets sold! (I sold 2myself)Seller #0 noticed all tickets sold! (I sold 2myself)Done use c++arrow_forwardIn the classic problem FizzBuzz, you are told to print the numbers from 1 to n. However,when the number is divisible by 3, print "Fizz''. When it is divisible by 5, print "Buzz''. When it isdivisible by 3 and 5, print"FizzBuzz''. In this problem, you are asked to do this in a multithreaded way.Implement a multithreaded version of FizzBuzz with four threads. One thread checks for divisibilityof 3 and prints"Fizz''. Another thread is responsible for divisibility of 5 and prints"Buzz''. A third threadis responsible for divisibility of 3 and 5 and prints "FizzBuzz''. A fourth thread does the numbers.arrow_forward
- 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