Question

In: Computer Science

If there are 32 concurrent processes, how will you modify the following code? Process i do...

If there are 32 concurrent processes, how will you modify the following code?

Process i

do {

while (turn == j);

               critical section;

turn = j;

               remainder section

} while (true);

Solutions

Expert Solution

There are two methods mostly common to handle the critical section:

method 1- Peterson's solution:

It is a classic based software solution to the critical-section problem. It is restricted to two processes that alternate execution between their critical sections and remainder sections. Peterson’ section requires two data items to be shared between the two processes i.e.

  • Int turn;
  • Boolean flag[2];

Variable turn indicates whose turn is to enter its critical section.

Flag array indicated whether the process is ready to enter its critical section.

If turn == i,

process Pi is allowed to enter in its critical section.

If flag[j] is TRUE,

process j is ready to enter in its critical section

Modified Code:

do{
    flag[i] = TRUE;
    turn = j;

    while(flag[j] && turn == j)
    
        critical section
        
    flag[i] = FALSE
    
        remainder section
    
}while(TRUE)

Method 2 - Semaphores:

It is a synchronization tool that is used to overcome the problems generated by the instructions,

TestAndSet()

Swap()

A semaphore S is an integer variable that can be accessed through two standard atomic operations that are

wait()

signal()

wait():

wait(S) {
   While S <= 0
   ; // no operation
   S--;
}

Signal():

signal(S) {
   S++;
}

When one process is modifying the value of semaphore then no other process can simultaneously manipulate the same semaphore value.

Code:

do{

waiting(mutex);

ciritical section

signal(mutex);

reminding section

}while(true)


Related Solutions

How do I start to code in mysql to Alter table to modify column remove not...
How do I start to code in mysql to Alter table to modify column remove not null constraint First drop the foreign key associated with Drop the column Add the column back with new definition Add the foreign key back This Is what I wrote so far alter table employees modify column repotsTo remove null:
Using Node.js as a Webserver 1. How do you modify a webserver.js code to include your...
Using Node.js as a Webserver 1. How do you modify a webserver.js code to include your name and date? Please include code. 2. Create a MongoDB database for the following group that includes member names and contact information and Include code: Gourp member exapmples: Pete 912-555-6666; Sam 912-111-3333; Mary 678-111-1111; and April 912-690-1111
2.     Modify assignment 1 solution code I posted to do the following: a.     Change car class to bankAccount...
2.     Modify assignment 1 solution code I posted to do the following: a.     Change car class to bankAccount class and TestCar class to TestBank class b.     Change mileage to balance c.     Change car info (make, model, color, year, fuel efficiency) to customer first and last name and account balance d.     Change add gas to deposit (without limit) e.     Change drive to withdraw cash f.  Change test car menu to the following Bank Account Menu choices 1 - Deposit 2 - Withdraw 3 - Display account info 4...
Modify the following code to use 'envp' instead of 'environ'. Be sure that you understand how...
Modify the following code to use 'envp' instead of 'environ'. Be sure that you understand how the code works. Provide liberal comments to explain what your pointer arithmetic is computing. Also, answer the following questions and explain your answers: i) WHERE in process memory is it most likely that each of the values exist at run time? ii) WHERE in process memory is it most likely the actual strings containing environment variables are stored? #include #include extern char **environ; //...
Could you modify my code so it meets the following requirement? (Python Flask) I want the...
Could you modify my code so it meets the following requirement? (Python Flask) I want the user to register for account using email and password, then store that data into a text file. Then I want the data to be read when logging in allowing the user to go to home page. -------------Code-------------------- routes.py from flask import Flask, render_template, redirect, url_for, request, session import json, re app = Flask(__name__) '''@app.before_request def before_request(): if 'visited' not in session: return render_template("login.html") else:...
I have to modify the following code to: 1. Use the unique algorithm to reduce the...
I have to modify the following code to: 1. Use the unique algorithm to reduce the array to unique values 2. Use the copy algorithm to display the unique results. #include<iostream> #include<vector> #include<algorithm> using namespace std; int main() {     //creating an array of 20 integers     int array[20];     //creating an empty vector     vector<int> vec;     //input from end user to get 20 ints and a for loop to interate through 20     cout << "Enter 20 integers:"...
How do you find the process ID of a specific process and kill the process? I...
How do you find the process ID of a specific process and kill the process? I am using python3 on a kali linux vm
I need to modify the following code (using Python3), where Groceries.csv is of following form (Item...
I need to modify the following code (using Python3), where Groceries.csv is of following form (Item on 1st column, price on 2nd) Stewing beef,15.45 Ground beef,11.29 Pork chops,11.72 Chicken,7.29 Bacon,7.12 Wieners,4.33 Canned salmon,5.68 Homogenized milk,5.79 Partly skimmed milk,5.20 Butter,4.99 Processed cheese slices,2.53 Evaporated milk,1.89 Eggs,3.11 Bread,2.74 Soda crackers,3.27 Macaroni,1.45 Flour,4.54 Corn flakes,5.72 Apples,4.71 Bananas,1.56 Oranges,3.70 ... a. In the function createPricesDict(), create a dictionary of each product mapped to its price. b. Suppose we have another dictionary for our cart...
look this code is a correct but i want modify it to allow the client to...
look this code is a correct but i want modify it to allow the client to have three attempts to login to the server package hw2; import java.net.*; import java.util.Formatter; import java.util.Random; import java.util.Scanner; import java.io.*; public class Client {    Socket server;    int port;    Formatter toNet = null;    Scanner fromNet = null;    Scanner fromUser = new Scanner(System.in);    public Client() {        try {            // login at server at local host...
look this code is a correct but i want modify it to allow the client to...
look this code is a correct but i want modify it to allow the client to have three attempts to login to the server package hw2; import java.net.*; import java.util.Formatter; import java.util.Random; import java.util.Scanner; import java.io.*; public class Client {    Socket server;    int port;    Formatter toNet = null;    Scanner fromNet = null;    Scanner fromUser = new Scanner(System.in);    public Client() {        try {            // login at server at local host...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT