CCR Deadlock

24
CCR Deadlock By: Laura Weiland April 30, 2002

description

CCR Deadlock. By: Laura Weiland April 30, 2002. Project Description. Implement a module to the Train Operating System (TOS) that manages the deadlock problem for the Computer Controlled Railroad (CCR). CCR Overview. Computer chips are imbedded each train. - PowerPoint PPT Presentation

Transcript of CCR Deadlock

Page 1: CCR Deadlock

CCR Deadlock

By: Laura Weiland

April 30, 2002

Page 2: CCR Deadlock

Project Description

Implement a module to the Train Operating System (TOS) that manages the deadlock problem for the Computer Controlled Railroad (CCR).

Page 3: CCR Deadlock

CCR Overview

• Computer chips are imbedded each train.

• Computer sends signals to the track that the chips in the trains detect.

• Photocells imbedded within the track that sense a change in light (i.e. a train passing by).

Page 4: CCR Deadlock

Lesson in Deadlock

• 4 Conditions Necessary for Deadlock– Mutual Exclusion: Only one train can hold a

resource (photocell(s)) at any given time.– Hold and Wait: A train may hold a resource

(photocell) while requesting another.– No Preemption: Resources (photocells) cannot

be taken from a train, the train must release them.

– Circular Wait: Two or more trains in a circular chain waiting for a resource (photocell) held by the next train in the chain.

Page 5: CCR Deadlock

Dealing with Deadlock

• Prevention: Ensure that one of the four conditions does not happen.

• Avoidance: A conservative allocation of resources. Only grant resources under safe conditions.

• Detection and Recovery: Grant any available resource with a way to detect and recover from deadlock should it occur.

• Ignore the Problem!

Page 6: CCR Deadlock

Inherited Train Operating System• Jeremy Vosters 2001 Senior Capstone Project

(TOS) - an Operating System for CCR– Operating System allows for multiple trains to run

under batch or interactive modes.– Managed active and blocked trains.– Stopped trains from colliding.– Ignores the problem of deadlock.

• Dr. McVey’s modifications to TOS– Allowed user to assign train starting positions.– Trains not allowed to start in a position where

resources are not available.

Page 7: CCR Deadlock

Building Blocks• Batch Processing

– Interactive processing allowed for various unknown variables.

– Inherited: Trains can move in a single direction around the track.

– Modifications made to allow trains to change direction within instruction cycle.

Page 8: CCR Deadlock

Building Blocks (Cont.)• Sliding Past Photocells

– Given the momentum of the trains while in motion, sudden stopping and/or changing directions can lead to trains sliding past desired photocells.

– Another variable was added to the train data type that indicates the last photocell it successfully departed from.

– If an arrival is issued for a train at the same photocell it has just departed, the train has slid past the photocell and the cursor to the train’s next instruction needs to be adjusted.

Page 9: CCR Deadlock

Deadlock Detection• The detection algorithm

is executed each time a train is added to the blocked train list.

• Detection Algorithm– Fill an indexed array with

the train id and blocking photocell for each train in the blocked train list.

– Search array for a circular pattern that would indicate deadlock.

Deadlock Detected

_________________ Deadlock Not

Detected

Page 10: CCR Deadlock

• Trains Blocked, No Deadlock

• Deadlock

Deadlock Detection (Cont.)

Page 11: CCR Deadlock

Deadlock Recovery• Once deadlock has been detected, the

recovery process begins.

• Recovery Algorithm– One train moves back an instruction in its

sequence, thus returning to the photocell it just came from.

– Blocked trains that now have resources available are released.

– The train that was moved back in its instruction sequence continues on from this point in its sequence.

Page 12: CCR Deadlock

Deadlock Recovery (Cont.)• Deciding which train to back up an instruction

– The train with the highest id number that can successfully back up an instruction.

• Algorithm not track specific.

• Decreases additional data structures and case statements.

• Recovering using trains in increasing id number resulted in two trains oscillating due to the release algorithm.

• Trains checked for recovery potential before recovery process put into motion.– Failure to do so could result in an infinite loop of

deadlock.

Page 13: CCR Deadlock

Deadlock Avoidance• “Yellow Light” Method of Avoidance

– A yellow signal indicates that the next section of track is clear, but that the following section is occupied or unsafe.

– As trains allocate their next section of track, they remove existing yellow flags and mark the section(s) following with a yellow flag(s).

– A train wishing to allocate a section of track that has been flagged yellow by another train will be blocked and its yellow light signal(s) are removed.

– This algorithm finds a basis in today’s railroad signaling.

Page 14: CCR Deadlock

Deadlock Avoidance (Cont.)Yellow Light Allocation Illustration

Page 15: CCR Deadlock

Deadlock Prevention

• Suggestion:– Trains going opposite directions can cause

deadlock quickly. Thus, only allow trains to move in one direction.

– If all trains are going a single direction, it would take 6 trains to create deadlock on this layout, thus allow only a maximum number of 5 trains on the track.

Page 16: CCR Deadlock

Resources Log• System states were recorded in a log for each

event handled by a train.– The log file has record of whether or not the

system is in a state of deadlock each time a train is added to the blocked trains list.

– Recovery steps are announced in the log file if deadlock was detected.

– Given the new deadlock solutions put in place, warning of an unsafe system state is known before deadlock will be detected.

Page 17: CCR Deadlock

Future Extension

Artificial Intelligence (AI)– Recovery methods could include AI techniques

that would take into consideration the probability of entering into another instance of deadlock.

Page 18: CCR Deadlock

Demonstration

Page 19: CCR Deadlock

Questions?

Page 20: CCR Deadlock

Strategies

• Break problem down into smaller, more manageable pieces.

• Design at a high-level before trying to implement algorithms.

• Test, test, and test again.

Page 21: CCR Deadlock

Knowledge

• Independent Study

• Operating Systems Course

Page 22: CCR Deadlock

Advice

• Plan ahead.

• Break problem down into manageable tasks.

• Use log files for testing purposes.

Page 23: CCR Deadlock

Overall Experience

• Brought out the science in computer science.

• Teaches organization, time management, experimentation, analysis, patients…

• Great preparation for graduate school.

Page 24: CCR Deadlock

Thank YouFor Coming!