1 CS170 2 3 4 Therac−25 5 6 1. Software problem #1 (our best guess) 7 8 A. Three threads: 9 10 −−Hand: sets the collimator/turntable position 11 12 −−Treat: sets a bunch of other parameters. Part of its job takes 13 eight seconds, during which time it’s ignoring everything else. 14 15 −−Vtkbp (keyboard handler): invoked when user types. It parses 16 the input, and writes to a two−byte shared variable, "MEOS" (mode/energy 17 offset) 18 −−"Treat" reads top byte, sets current and energy 19 −−"Hand" reads bottom byte, sets the collimator/turntable position 20 21 B. Pseudocode: 22 23 Vtkbp (gets and parses keyboard input): 24 25 data_completion_flag = 0 26 27 while (1) { 28 wait_for_keyboard_activity(); 29 /* there was some keyboard activity; let’s check it */ 30 if (cursor_in_bottom_right) { 31 parse_the_input(); 32 set the MEOS variable 33 set data_completion_flag = 1; 34 signal hand thread 35 signal treat thread 36 } else { 37 /* operator still typing */ 38 data_completion_flag = 0; 39 } 40 yield(); 41 } 42 43 44 Hand (sets the turntable position): 45 46 while (1) { 47 wait until signalled 48 read bottom byte of MEOS variable 49 /* next line executes quickly */ 50 set turntable position 51 yield(); 52 } 53 54 Treat (sets a bunch of parameters and delivers treatment): 55 56 dataent() { /* this is a subroutine that was called */ 57 58 while (1) { 59 wait until signalled 60 read top byte of MEOS variable 61 set_energy_and_current(); 62 set_bending_magnets(); /* this takes eight seconds */ 63 if (data_completion_flag == 1) 64 break; 65 } 66 /* 67 * now we leave the subroutine and progress to a state in 68 * which the machine will accept a "beam on" command 69 */ 70 return; 71 } 72 73 2. Software problem #2 (simplified) 74 75 [Simplifying here and condensing to one thread of control; in 76 reality, the functions below are spread over two different threads, 77 but that is not actually the problem, despite what the paper 78 sometimes says. The problem appears to be given by the following 79 simplified description.] 80 81 class3 = 0; 82 83 while (1) { 84 85 if (in field light position) { 86 increment class3; 87 } 88 89 check whether operator pressed "set" 90 91 if (operator pressed set) { 92 if (class3 != 0) { 93 move turntable out of field light mode; 94 } 95 break; 96 } 97 } 98 99 What’s the issue here? (Hint: class3 is only one byte.) 100