Here is a sequence of operations by two concurrently executing threads (Th1 and
ID: 3558466 • Letter: H
Question
Here is a sequence of operations by two concurrently executing threads (Th1 and Th2) on a uniprocessor with execution times T0 to T6. We assume for this exercise that context switches take no time. Shared memory at address 0x1008 is initialized to 5:
T0: Th1 register1 = memory at address 0x1008
T1: Th1 register1 = register1 + 1
T2: Th2 register2 = memory at address 0x1008
T3: Th2 register2 = register2 - 1
T4: Th1 memory at address 0x1008 = register1
T5: Th2 memory at address 0x1008 = register2
T6: Th1 your answers come from this time period after the context switch but before anything executes here.
8. What is the value of register1 at T6? _____
9. What is the value of register2 at T6? _____
10. What is the value of memory at address 0x1008 at T6? _____
Explanation / Answer
Sequence of actions of Thread1 from time to time:
Time
Action
T0
Register1 is loaded with value 5
T1
Value of register1 is changed to 6
T2
-----
T3
-----
T4
Shared memory value is changed to 6
T5
-----
T6
-----
Sequence of actions of Thread2 actions from time to time:
Time
Action
T0
-----
T1
-----
T2
Register2 is loaded with value 5
T3
Value of register2 is changed to 4
T4
-----
T5
Shared memory value is changed to 4
T6
-----
8)
The value of register1 at T6 is 6, because in actions of Thread1, at time T1, register1 value is changed to value 5(shared memory value). After T1, register1 is not updated to any other new value. Hence value of register1 at T6 is 6 only.
9)
The value of register2 at T6 is 4, because in Thread2 actions, at time T2, register2 value is changed to 4. After T2, register2 is not updated to any new value. Hence value of register1 at T6 is 4 only.
10)
The value of memory at address 0x1008 at T6 is 4. Observe both tables. The shared memory will contain the value which is last updated. At time T5 in Thread1, shared memory value is changed from value 5 to 6(register1 value). But, after T5, at time T6 in Thread2, shared memory value is changed from value 6 to 4(register2 value).
Time
Action
T0
Register1 is loaded with value 5
T1
Value of register1 is changed to 6
T2
-----
T3
-----
T4
Shared memory value is changed to 6
T5
-----
T6
-----