In the corrected codes show the critical sections

Assignment Help Other Subject
Reference no: EM132586050

Assignment -

The local Bridge is undergoing repairs and only one lane is open for traffic. To prevent accidents, traffic lights have been installed at either end of the bridge to synchronize the traffic going in different directions. A car can only cross the bridge if there are no cars going the opposite direction on the bridge. Sensors at either end of the bridge detect when cars arrive and depart from the bridge, and these sensors control the traffic lights.

Below is a skeleton implementation of two routines: Arrive() and Depart(). You may assume that each car is represented by a thread, and threads call Arrive() when they arrive at the bridge and Depart() when they leave the bridge. Threads pass in their direction of travel as input to the routines.

int num_cars = 0;

enum dir = {open, north, south};

dir cur_dir =open;

1. void Arrive (dir my_dir) {

A0: while (cur_dir 1= my_dir I 1 cur_dir 1= open) {

A1: num cars++;

A2: cur dir = my_dir;

2. void Depart (dir my_dir) {

D0: num_cars--;

D1: if (num_cars == 0) {

D2: cur_dir = open;

(a) The code given above does not have any synchronization statements. Outline an execution sequence (referring to the numbered statements) where two threads can cause two cars to travel on the bridge in opposite directions at the same time.

(b) Show how condition variables with explicit locks could be used to correctly synchronize the cars by adding the necessary calls to Condition and Lock operations in the given code with appropriate initializations.

(c) In the corrected codes, show the critical sections.

(d) Can this solution lead to starvation? Briefly explain.

Reference no: EM132586050

Questions Cloud

Topics associated with the cloud : Pick one of the following topics associated with the cloud and research it accordingly.
Describe how amazon either does or does not apply : Describe how Amazon either does or does not apply the course concepts on a day-to-day basis. The following course concepts should be discussed
Determine the probabilities of all possible phenotypes : Hemophilia is sex-linked but this form of albinism is autosomal. Both conditions are inherited as recessives.
Topic of color can be a minefield : Kirk (2016) states that the topic of color can be a minefield.
In the corrected codes show the critical sections : The local Bridge is undergoing repairs and only one lane is open for traffic. In the corrected codes show the critical sections
Briefly summarize the patient case study you were assigned : Briefly summarize the patient case study you were assigned, including each of the three decisions you took for the patient presented.
What happen during an action potential : What happen during an action potential?
Annotation and color : According to Kirk (2016), typography will have a significant role in your visualizations.
Do you have input into design decisions : What is your role as an advocate for your target population for this healthcare program? Do you have input into design decisions? How else do you impact design?

Reviews

Write a Review

Other Subject Questions & Answers

  Cross-cultural opportunities and conflicts in canada

Short Paper on Cross-cultural Opportunities and Conflicts in Canada.

  Sociology theory questions

Sociology are very fundamental in nature. Role strain and role constraint speak about the duties and responsibilities of the roles of people in society or in a group. A short theory about Darwin and Moths is also answered.

  A book review on unfaithful angels

This review will help the reader understand the social work profession through different concepts giving the glimpse of why the social work profession might have drifted away from its original purpose of serving the poor.

  Disorder paper: schizophrenia

Schizophrenia does not really have just one single cause. It is a possibility that this disorder could be inherited but not all doctors are sure.

  Individual assignment: two models handout and rubric

Individual Assignment : Two Models Handout and Rubric,    This paper will allow you to understand and evaluate two vastly different organizational models and to effectively communicate their differences.

  Developing strategic intent for toyota

The following report includes the description about the organization, its strategies, industry analysis in which it operates and its position in the industry.

  Gasoline powered passenger vehicles

In this study, we examine how gasoline price volatility and income of the consumers impacts consumer's demand for gasoline.

  An aspect of poverty in canada

Economics thesis undergrad 4th year paper to write. it should be about 22 pages in length, literature review, economic analysis and then data or cost benefit analysis.

  Ngn customer satisfaction qos indicator for 3g services

The paper aims to highlight the global trends in countries and regions where 3G has already been introduced and propose an implementation plan to the telecom operators of developing countries.

  Prepare a power point presentation

Prepare the power point presentation for the case: Santa Fe Independent School District

  Information literacy is important in this environment

Information literacy is critically important in this contemporary environment

  Associative property of multiplication

Write a definition for associative property of multiplication.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd