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)
- A group of philosophers are seated around a circular table with one chopstick in between each of them in the classic dining philosophers conundrum. A philosopher usually takes up the left chopstick before the right one while using both chopsticks to eat. If all the philosophers reached for the left chopstick at once, there may be a deadlock. Implement a simulation of the dinner philosophers issue that avoids deadlocks using threads and locks.arrow_forwardWrite a program that launches 26 threads. Each thread represents an English alphabet, say a, b, c, etc. Each thread should concatenate the string "+ ch " to a string variable that is initially defined as the string " " (i.e. empty string). "ch" represents the character of the current thread being executed (e.g. a, b, c,..) . Print your string variable after all threads have been executed. The targeted correct output may look like "a+b+c+d+e+…..". Run the program with and without synchronization to see its effect. Comment on the non-synchronized output.arrow_forwardGive an example of the progress graph for a pair of threads that use two semaphores for mutual exclusion.arrow_forward
- 3. Implement mutual exclusion with multithreading in Java Build a Java program which simulates a communication between a server and clients. You must use a thread to represent each party (as server or client). (Hint: study about the Semaphore class to perform mutual exclusion between threads) Create three threads. One thread will act as a server, which always ready to receive a message from a client (ping) and then replies the message to the same client (pong). The other two threads will become the clients, where each client will send a message to the server (ping) and waits for the reply (pong). Define 2 different classes to represent the server and the client. To perform the communication, each thread will refer to a same variable/data structure for sending and receiving the message. Use mutual exclusion approach to ensure each client can send and receive the reply without interruption from any other client(s). For this simulation, your objective is to ensure that each client must…arrow_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_forwardImplement a Queue class whose add and remove methods are synchronized. Supply one thread, called the producer, which keeps inserting strings into the queue as long as there are fewer than ten elements in it. When the queue gets too full, the thread waits. As sample strings, simply use time stamps new Date().toString(). Supply a second thread, called the consumer, that keeps removing and printing strings from the queue as long as the queue is not empty. When the queue is empty, the thread waits. Both the consumer and producer threads should run for 100 iterations.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_forwardImplement a program which gets the thread number and add it to a tsum variable. int tsum=0;#pragma omp paralleltsum += omp_get_thread_num();printf("Sum is %d\n", tsum); Compile and run it several times. Do you see something unexpected? what problem are you expecting? How can we solve it?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
- 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_forwardJAVA You are requested to implement a “message buffer and response connector” class using Javaprogramming language. The following figure depicts a message buffer and response connectorclass, followed by detailed operations specifications. The message buffer and response connectorclass has three operations, send(), receive(), and reply().Your program should create two separate threads for testing your implementation, a producerthread, and a consumer thread. The producer thread sends a message having a structure (string,integer) – e.g., (add, 3) or (multiply, 7) - to a consumer thread via a message buffer and responseconnector. The consumer thread encapsulates a SimpleCalculation class that has two operations,add() and “multiply(). You should implement the SimpleCalculation class as well. When theconsumer thread receives a message from the connector, it extracts the message and then callsone of the operations on the SimpleCalculation class, depending on the message. For example,the…arrow_forwardWrite a C program to implement threading.a. Use following two Arraysa. Student ID[]={101,102,103,104,105}b. Student Results[]={85,45,55,65,75}b. Thread1 prints the student IDs of those students who has 1st and 2nd highest marks.c. Thread 2 prints the IDs of failed studentsd. Thread3 prints avg marks of the classarrow_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