taocp

This site has no text of the book. Keep your own copy of TAOCP next to it. See what is checked.

Exercise · Volume 1 · 2.2.5-7

Exercise 2.2.5-7

not stated yet in Lean solution written

Rating25
KindInformal: the exercise has no formal statement, so Lean does not state it from the written solution
SectionSection 2.2.5 of Volume 1

The task

In the first version, line 154 of the program read JANZ CYCLE instead of JANZ U4A. Say what the error was.

The exact wording is in your copy of the book.

Hints

Open one hint at a time. Try the exercise again after each.

Hint 1

Ask where the node of the user is when step U4 is executed, and where it must be afterwards.

Solution

Show the solution

Every user node that waits is in the WAIT list. When the node comes to the front, the routine CYCLE removes it from that list and jumps to the stored instruction, so in step U4 the node of the user is in no WAIT list. Line 154 is reached when the elevator is at the floor of the user with D1≠0D1 \ne 0, which means that the user stays in the queue. With JANZ CYCLE the node would not be put back into the WAIT list, and the simulation would go on without it.

Later, step E4 takes the front person of the queue of that floor and in line 227 deletes the node from the WAIT list in order to cancel the action U4. It assumes that the node is in the WAIT list. Here it is not, and the links of the node are old values. The deletion changes the links of two nodes that are in the list, to the old neighbours, and the WAIT list becomes wrong, possibly with nodes lost or the list cut. The jump to U4A puts the user back with a new waiting time of GIVEUPTIME\mathrm{GIVEUPTIME}, and this keeps the assumption true. It also needs the waiting time to be positive, as it is, since otherwise the node would be taken at once again.

Remarks

This is a bug of the kind that shows only in a rare situation, a user who is about to give up at the very moment the elevator is at the floor.

This solution is drafted, and a person has not reviewed it yet. The source.

In Lean

not stated yet The exercise is not stated in Lean yet.

The status is computed from the Lean build. The node of the map.

Something is wrong? Report it.