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

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
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:...
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...
Below are the control strategy of hydraulic hybrid vehicle. How can I modify code below to...
Below are the control strategy of hydraulic hybrid vehicle. How can I modify code below to include the torque of motor of hydraulic hybrid vehicle? and How can I improve this function [SOC,k,T_engine,S_engine,T_brake,T_pump] = strategy(duration,gamma,P,V,Pmin,Pmax,Vmin,Vmax,SOC,Disp,T_wheel,S_wheel,gearratio,S_map,Te_max,T_engine,S_engine,T_pm,k,eff_mech,eff_hyd) S_flywheel = S_wheel*gearratio; T_flywheel = T_wheel/gearratio; T_brake = 0; if SOC < 0.1 k=1; %Engine on elseif SOC > 0.7 k=0; %Engine off end %T_pump +ve = charging %T-pump -ve = discharging if k==1 if T_engine*eff_mech < T_flywheel    %Engine provides full torque when hydraulic...
c++ /*USE STARTER CODE AT THE BOTTOM AND DO NOT MODIFY ANY*/ This is the entire...
c++ /*USE STARTER CODE AT THE BOTTOM AND DO NOT MODIFY ANY*/ This is the entire assignment. There are no more directions to it. Create an array of struct “employee” Fill the array with information read from standard input using C++ style I/O Shuffle the array Select 5 employees from the shuffled array Sort the shuffled array of employees by the alphabetical order of their last Name Print this array using C++ style I/O Random Number Seeding We will make...
JAVA- How do I edit the following code as minimally as possible to add this method...
JAVA- How do I edit the following code as minimally as possible to add this method for calculating BMI? BMI Method: public static double calculateBMI(int height, int weight) { double BMI = (((double) weight) * 0.453592d) / ((((double) height) * 0.0254) * (((double) height) * 0.0254)); Format f = new DecimalFormat("##.######"); return (f.format(BMI)); } Code: import java.text.DecimalFormat; import java.util.Scanner; public class test2 { public static void main(String[] args) { DecimalFormat f = new DecimalFormat("##.0"); Scanner reader = new Scanner(System.in); System.out.printf("%10s...
Why are the following business processes important? Which process do you feel is most important? Explain...
Why are the following business processes important? Which process do you feel is most important? Explain your reasoning. Strategy development Product development Systems to produce goods and services Order fulfillment
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT