ACS-4902 Assignment 5 Regarding Figure 17.3 a) Schedule under consideration: time T1 T2 1 Read_item(X) 2 X:=X-N 3 Read_item(X) 4 X:=X+M 5 Write_item(X) 6 Read_item(X) 7 Write_item(X) 8 Y:=Y+N 9 Write_item(Y) i) At time 5, T1 requests a write lock on X. This cannot be granted since T2 holds a read lock. Wait-die specifies the older requesting transaction T1 can wait. But later, T2 will request a write lock on X … wait-die specifies the younger requesting transaction dies and so we must have time 1 2 3 4 5 T1 (older) Read_item(X) X:=X-N Read_item(X) X:=X+M Write_item(X) -suspended 6 7 8 9 10 11 T2 (younger) Write_item(X) -aborted Write_item(X) -resumes Read_item(Y) Y:=Y+N Write_item(Y) Commit Could be restarted i.e. {R1(X), R2(X), abort2, W1(X), R1(Y), W1(Y), commit1} ii) At time 5, T1 requests a write lock on X. This cannot be granted since T2 holds a read lock. Wound-wait specifies the older requesting transaction T1 wounds the younger transaction T2, and so we have time T1 (older) Read_item(X) X:=X-N T2 (younger) 1 2 3 Read_item(X) 4 X:=X+M 5 Write_item(X) aborted 6 Read_item(Y) 7 Y:=Y+N 8 Write_item(Y) 9 Commit 10 Could be restarted 11 i.e. {R1(X), R2(X), abort2, W1(X), R1(Y), W1(Y), commit1} iii) With deadlock detection a cycle appears in the solution below at time 6 and one of T1, T2 is chosen as the victim and rolled back, and so can have Either: time 1 2 3 4 5 T1 Read_item(X) X:=X-N Read_item(X) X:=X+M Write_item(X) -suspended 6 7 T2 Write_item(X) -suspended -aborted due to deadlock detection Write_item(X) -resumes Read_item(Y) Y:=Y+N Write_item(Y) Commit 8 9 10 11 12 Could be restarted i.e. {R1(X), R2(X), abort2, W1(X), R1(Y), W1(Y), commit1} OR: time 1 2 3 4 5 T1 Read_item(X) X:=X-N Read_item(X) X:=X+M Write_item(X) -suspended 6 7 8 T2 Write_item(X) -suspended -aborted due to deadlock detection Write_item(X) -resumes Commit 9 10 Could be restarted 11 12 i.e. {R1(X), R2(X), abort1, W2(X), commit2} b) Schedule under consideration: time T1 T2 1 Read_item(X) 2 X:=X-N 3 Write_item(X) 4 Read_item(X) 5 X:=X+M 6 Write_item(X) 7 Read_item(Y) 8 9 i) At time 4, T2 requests a read lock on X. This cannot be granted since T1 holds a write lock. Wait-die specifies the younger requesting transaction T2 dies, and so we must have time 1 2 3 4 T1 (older) Read_item(X) X:=X-N Write_item(X) T2 (younger) Read_item(X) -aborted 5 Read_item(Y) 6 Commit 7 Could be restarted 8 9 i.e. {R1(X), W1(X), abort2, R1(Y), commit1} ii) At time 4, T2 requests a read lock on X. This cannot be granted since T2 holds a read lock. Wound-wait specifies the younger requesting transaction T2 waits, and so we have time 1 2 3 4 5 6 7 8 9 10 T1 (older) Read_item(X) X:=X-N Write_item(X) T2 (younger) Read_item(X) -suspended Read_item(Y) Commit Read_item(X) -resumes X:=X+M Write_item(X) Commit i.e. {R1(X), W1(X), R1(Y), commit1, R2(X), W2(X), commit2} iii) With deadlock detection no cycles appear (only T2 is waiting) and so time 1 2 3 4 5 6 7 8 9 10 T1 (older) Read_item(X) X:=X-N Write_item(X) T2 (younger) Read_item(X) -suspended Read_item(Y) Commit Read_item(X) -resumes X:=X+M Write_item(X) Commit i.e. {R1(X), W1(X), R1(Y), commit1, R2(X), W2(X), commit2} c) Schedule under consideration: time T1 T2 1 SUM:=0 2 Read_item(A) 3 Sum:=SUM+A 4 … 5 Read_item(X) 6 X:=X-N 7 Write_item(X) 8 Read_item(X) 9 SUM:=SUM+X 10 Read_item(Y) 11 SUM:=SUM+Y 12 Read_item(Y) 13 Y:=Y+N 14 Write_item(Y) i) At time 8 T2 requests a read lock on X, but this cannot be granted since T1 holds a write lock on X. With wait-die, T2 waits since it is older and so: time 1 2 3 4 5 6 7 8 9 10 11 12 13 T1 T3 SUM:=0 Read_item(A) Sum:=SUM+A … Read_item(X) X:=X-N Write_item(X) Read_item(X) -suspended Read_item(Y) Y:=Y+N Write_item(Y) Commit Read_item(X) -resumes 14 SUM:=SUM+X 15 Read_item(Y) 16 SUM:=SUM+Y 17 Commit i.e. {R3(A), R1(X), W1(X), R1(Y), W1(Y), commit1, R3(X), R3(Y), commit3} ii) At time 8 T2 requests a read lock on X, but this cannot be granted since T1 holds a write lock on X. With wound-wait, T2 wounds T1 since T2 is older and so : time T1 T3 1 SUM:=0 2 Read_item(A) 3 Sum:=SUM+A 4 … 5 Read_item(X) 6 X:=X-N 7 Write_item(X) 8 aborted Read_item(X) 9 SUM:=SUM+X 10 Read_item(Y) 11 SUM:=SUM+Y 12 Commit 13 Could be restarted 14 i.e. {R3(A), R1(X), W1(X), abort1, R3(X), R3(Y), commit3} iii) At time 8 T2 requests a read lock on X, but this cannot be granted since T1 holds a write lock on X. With deadlock detection and only T2 waiting : time 1 2 3 4 5 6 7 8 9 10 11 12 13 T1 T3 SUM:=0 Read_item(A) Sum:=SUM+A … Read_item(X) X:=X-N Write_item(X) Read_item(X) -suspended Read_item(Y) Y:=Y+N Write_item(Y) Commit Read_item(X) -resumes 14 SUM:=SUM+X 15 Read_item(Y) 16 SUM:=SUM+Y 17 Commit i.e. {R3(A), R1(X), W1(X), R1(Y), W1(Y), commit1, R3(X), R3(Y), commit3}
© Copyright 2025 Paperzz