Loop Race Conditions
- Due Oct 24, 2019 at 11:59pm
- Points 13
- Questions 13
- Time Limit None
- Allowed Attempts Unlimited
Instructions
Generated from the OSTEP homework with the command:
x86.py -p looping-race-nolock.s -t 2 -R ax -M 2000 -i 4 -r -a bx=4 -c -s 100
Consider the following assembly code:
# assumes %bx has loop count in it
.main
.top
# critical section
mov 2000, %ax # get the value at the address
add $1, %ax # increment it
mov %ax, 2000 # store it back
# see if we're still looping
sub $1, %bx
test $0, %bx
jgt .top
halt
Assume threads execute the code and context switches (interrupts) occur after the instructions execute as shown. What will be the contents of memory address 2000 and the %ax register? %bx starts with the value of 4.
Instr 2000 ax Thread 0 Thread 1
1 ? ? 1000 mov 2000, %ax
2 ? ? ------ Interrupt ------ ------ Interrupt ------
3 ? ? 1000 mov 2000, %ax
4 ? ? 1001 add $1, %ax
5 ? ? ------ Interrupt ------ ------ Interrupt ------
6 ? ? 1001 add $1, %ax
7 ? ? 1002 mov %ax, 2000
8 ? ? 1003 sub $1, %bx
9 ? ? 1004 test $0, %bx
10 ? ? ------ Interrupt ------ ------ Interrupt ------
11 ? ? 1002 mov %ax, 2000
12 ? ? 1003 sub $1, %bx
13 ? ? 1004 test $0, %bx
14 ? ? ------ Interrupt ------ ------ Interrupt ------
15 ? ? 1005 jgt .top
16 ? ? 1000 mov 2000, %ax
17 ? ? 1001 add $1, %ax
18 ? ? ------ Interrupt ------ ------ Interrupt ------
19 ? ? 1005 jgt .top
20 ? ? 1000 mov 2000, %ax
21 ? ? ------ Interrupt ------ ------ Interrupt ------
22 ? ? 1002 mov %ax, 2000
23 ? ? 1003 sub $1, %bx
24 ? ? 1004 test $0, %bx
25 ? ? 1005 jgt .top
26 ? ? ------ Interrupt ------ ------ Interrupt ------
27 ? ? 1001 add $1, %ax
28 ? ? 1002 mov %ax, 2000
29 ? ? 1003 sub $1, %bx
30 ? ? ------ Interrupt ------ ------ Interrupt ------
31 ? ? 1000 mov 2000, %ax
32 ? ? ------ Interrupt ------ ------ Interrupt ------
33 ? ? 1004 test $0, %bx
34 ? ? 1005 jgt .top
35 ? ? ------ Interrupt ------ ------ Interrupt ------
36 ? ? 1001 add $1, %ax
37 ? ? ------ Interrupt ------ ------ Interrupt ------
38 ? ? 1000 mov 2000, %ax
39 ? ? 1001 add $1, %ax
40 ? ? 1002 mov %ax, 2000
41 ? ? 1003 sub $1, %bx
42 ? ? ------ Interrupt ------ ------ Interrupt ------
43 ? ? 1002 mov %ax, 2000
44 ? ? 1003 sub $1, %bx
45 ? ? 1004 test $0, %bx
46 ? ? 1005 jgt .top
47 ? ? ------ Interrupt ------ ------ Interrupt ------
48 ? ? 1004 test $0, %bx
49 ? ? 1005 jgt .top
50 ? ? ------ Interrupt ------ ------ Interrupt ------
51 ? ? 1000 mov 2000, %ax
52 ? ? 1001 add $1, %ax
53 ? ? ------ Interrupt ------ ------ Interrupt ------
54 ? ? 1000 mov 2000, %ax
55 ? ? 1001 add $1, %ax
56 ? ? 1002 mov %ax, 2000
57 ? ? 1003 sub $1, %bx
58 ? ? ------ Interrupt ------ ------ Interrupt ------
59 ? ? 1002 mov %ax, 2000
60 ? ? ------ Interrupt ------ ------ Interrupt ------
61 ? ? 1004 test $0, %bx
62 ? ? ------ Interrupt ------ ------ Interrupt ------
63 ? ? 1003 sub $1, %bx
64 ? ? ------ Interrupt ------ ------ Interrupt ------
65 ? ? 1005 jgt .top
66 ? ? 1006 halt
67 ? ? ----- Halt;Switch ----- ----- Halt;Switch -----
68 ? ? ------ Interrupt ------ ------ Interrupt ------
69 ? ? 1004 test $0, %bx
70 ? ? 1005 jgt .top
71 ? ? 1006 halt
Only registered, enrolled users can take graded quizzes