This homework is about Process/Thread Synchronization. Please label your answers
ID: 3591995 • Letter: T
Question
This homework is about Process/Thread Synchronization. Please label your answers a) and b) so I know which one is which. Thanks!!!
HERE IS THE GIVEN CODE TO USE TO ANSWER PARTS A) AND B)
3. Consider simulating a roller coaster amusement ride with one car of capacity CAPACITY passengers. The passengers arrive, wait until the car is ready for boarding, then board (one by one). When the roller coaster car is full, it leaves for the ride. When it returns, the passengers leave the car (no leaving in the middle of the ride!). When all passengers have left the car, new passengers can start boarding. a) Is it possible that a passenger enjoys the ride before the roller coaster car has left (that is prints the message before the ride starts)? If no, justify why. If yes, correct the code you may need to introduce a new semaphore or so. (No need to fully rewrite the code here, you may write/insert into the code provided on the next page.) b) Assume there are VIPs who would also like to take a ride. However a VIP is so important and has bodyguards, so he/she will use 5 spaces instead of 1. Moreover, VIPs don't like to wait: if VIP boards, the roller coaster car should leave even if it is nowhere near full. If there are less then 5 spaces left, the VIP cannot fit and the roller coaster car must leave (without the VIP) so it returns sooner and the VIP does not wait unnecessarily. Your task: Write the code for the VIP. Make sure that even if there are plenty of waiting passengers and the VIP process boards the roller coaster car first (assume that the VIP process has the same scheduling priority as the other processes).Explanation / Answer
static public int BuildTrack(Direction direction,
List<Object3D> myTracks, ref List<Direction> directions)
{
//No Building Tracks IF Coaster is finshed, this is a fail safe.
if (CoasterFinshed)
{
return 0;
}
Object3D track = new Object3D();
Vector3 newOrientation = new Vector3();
Vector3 newLocation = new Vector3();
Vector3 LastOrientation = new Vector3();
//Find Where Next Track would be
if (myTracks.Count > 0)
{
LastOrientation = new Vector3(myTracks.Last<Object3D>().Orientation.X,
myTracks.Last<Object3D>().Orientation.Y, myTracks.Last<Object3D>().Orientation.Z);
newOrientation = new Vector3(myTracks.Last<Object3D>().Orientation.X,
myTracks.Last<Object3D>().Orientation.Y, myTracks.Last<Object3D>().Orientation.Z);
newLocation = new Vector3(myTracks.Last<Object3D>().Location.X,
myTracks.Last<Object3D>().Location.Y, myTracks.Last<Object3D>().Location.Z);
}
else
{
LastOrientation = new Vector3();
newOrientation = new Vector3(0, 270, 0);
newLocation = new Vector3(0, 0, -40);
}
newOrientation = GetNewOrientation(newOrientation, direction);
newLocation = GetNewLocation(newOrientation, newLocation, LastOrientation);
track.Location = newLocation;
track.Orientation = newOrientation;
track.Scale = new Vector3(Constants.TRACK_SCALE, Constants.TRACK_SCALE, Constants.TRACK_SCALE);
//
if (iqnoreAllButStandard)
{
//Build The Track Standard
directions.Add(direction);
myTracks.Add(track);
return 1;
}
else if (iqnoreFinshArea == false && InFinshArea(newLocation))
{
directions.Add(direction);
myTracks.Add(track);
FinshCoaster(myTracks, ref directions, 1);
return 0;
}
else if (iqnoreAutoLoop == false && AutoLoop(myTracks, ref directions))
{
return 0;
}
else if (iqnoreCollision == false && CollisionDetected(newLocation, myTracks))
{
return 0;
}
else if (iqnoreFlaten == false && Flaten(myTracks, direction, track,
newOrientation, newLocation, LastOrientation, ref directions))
{
return 0;
}
if (iqnoreTracksToLow == false && TrackToLow(newLocation, newOrientation))
{
return 0;
}
else if (iqnoreBounceOffWall == false && BounceOffWall(newLocation, direction, myTracks, ref directions))
{
return 0;
}
else if (iqnoreOutOfBounds == false && OutOfBounds(newLocation))
{
return 0;
}
else
{
//Build The Track Standard
directions.Add(direction);
myTracks.Add(track);
return 1;
}
Draw loop
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
GraphicsDevice.BlendState = BlendState.Opaque;
GraphicsDevice.Clear(Color.CornflowerBlue);
//Layout
drawManager.DrawModel(layoutModel, new Microsoft.Xna.Framework.Vector3(0, 0, 0),
new Microsoft.Xna.Framework.Vector3(0, 0, 0), new Microsoft.Xna.Framework.Vector3(.25f, .25f, .25f));
//Tracks
for (int i = 0; i < core.Tracks.Count; i++)
{
drawManager.DrawModel(trackModel,
new Microsoft.Xna.Framework.Vector3(core.Tracks[i].Location.X,
core.Tracks[i].Location.Y, core.Tracks[i].Location.Z),
new Microsoft.Xna.Framework.Vector3(core.Tracks[i].Orientation.X,
core.Tracks[i].Orientation.Y, core.Tracks[i].Orientation.Z),
new Microsoft.Xna.Framework.Vector3(RollerCoaster.Constants.TRACK_SCALE,
RollerCoaster.Constants.TRACK_SCALE, RollerCoaster.Constants.TRACK_SCALE));
}
//Cart
drawManager.DrawModel(cartModel,
new Microsoft.Xna.Framework.Vector3(core.Cart.Location.X,
core.Cart.Location.Y, core.Cart.Location.Z),
new Microsoft.Xna.Framework.Vector3(core.Cart.Orientation.X,
core.Cart.Orientation.Y, core.Cart.Orientation.Z),
new Microsoft.Xna.Framework.Vector3(RollerCoaster.Constants.CART_SCALE,
RollerCoaster.Constants.CART_SCALE, RollerCoaster.Constants.CART_SCALE));
spriteBatch.Begin();
//Menu
DrawMenu();
//Draw Mouse
MouseState currentMouseState = Mouse.GetState();
float mouseX = (1980.0f / GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width) * currentMouseState.X;
float mouseY = (1080.0f / GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height) * currentMouseState.Y;
Microsoft.Xna.Framework.Vector2 posMouse = new Microsoft.Xna.Framework.Vector2(mouseX, mouseY);
spriteBatch.Draw(pointer, posMouse, Color.White);
spriteBatch.End();
//Clean Up
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
base.Draw(gameTime);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.