0% found this document useful (0 votes)
25 views3 pages

Distributed S2

Uploaded by

sampopper46
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views3 pages

Distributed S2

Uploaded by

sampopper46
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

‫محمود عادل احمد الرياش الرياش‬.

20201474143

Problem 1 :

Schedule with Lost Update:

T1: Read(A), Read(B), Write(A), Write(B)

T2: Read(B), Read(C), Write(B), Write(C)

T3: Read(A), Read(B), Read(C), Write(A), Write(B), Write(C)

This schedule results in a lost update as the final values of A, B, C are affected by interleaving the
write operations of T1, T2, T3.

Using Locks to Prevent Lost Update:

you can use locks. For example, you can use a write lock to ensure exclusive access to the data items
during write operations. In this scenario, each transaction would acquire a write lock before
performing a write operation and release it afterward.

Schedule with Locks to Ensure No Lost Updates:

T1: Write Lock(A), Read(A), Write Lock(B), Read(B), Write(A), Write(B), Release Lock(A, B)

T2: Write Lock(B), Read(B), Write Lock(C), Read(C), Write(B), Write(C), Release Lock(B, C)

T3: Write Lock(A, B, C), Read(A), Read(B), Read(C), Write(A), Write(B), Write(C), Release Lock(A, B, C)

By using write locks, we make sure that a transaction has exclusive access to the data items it is
writing to, preventing lost updates.

Problem 2:

1. Final Values Without Control Mechanisms:**

Without control mechanisms, the final values of A and B could be inconsistent due to interleaving
of read and write operations in T1 and T2. For example:

- T1: Read(A), Read(B), Write(A), Write(B)

- T2: Read(B), Read(A), Write(B), Write(A)

The final values might vary depending on the interleaving, leading to potential inconsistencies.
2. Using Locks to Ensure Consistency:**

To ensure consistency, you can use locks. For example, you can use write locks to ensure exclusive
access to the accounts during write operations, preventing interleaving and maintaining consistency.

3. Schedule with Locks to Ensure Consistency:**

- T1: **Write Lock(A, B)**, Read(A), Read(B), Write(A), Write(B), **Release Lock(A, B)**

- T2: **Write Lock(B, A)**, Read(B), Read(A), Write(B), Write(A), **Release Lock(B, A)**

By using write locks, we ensure that a transaction has exclusive access to the accounts it is reading
from and writing to, ensuring inconsistencies.

Problem 3:

1. Final Values Without Control Mechanisms:

Without control mechanisms, the final values of A, B, and C could be inconsistent due to
interleaving of read and write operations in T1, T2, and T3. The final values might vary depending on
the interleaving, leading to potential inconsistencies.

2. Using Locks to Prevent Inconsistency:

To prevent inconsistency, you can use locks. For example, you can use write locks to ensure
exclusive access to the accounts during write operations, preventing interleaving and maintaining
consistency.

3. Schedule with Locks to Ensure Consistency:

- T1: Write Lock(A, B), Read(A), Read(B), Write(A), Write(B), Release Lock(A, B)

- T2: Write Lock(B, C), Read(B), Read(C), Write(B), Write(C), Release Lock(B, C)

- T3: Write Lock(C, A), Read(C), Read(A), Write(C), Write(A), Release Lock(C, A)

By using write locks, we ensure that a transaction has exclusive access to the accounts it is reading
from and writing to, preventing inconsistencies

Problem 4 :
1. Issues Without Proper Transaction Management:

Without proper transaction management, several issues can arise:

- Lost Update: Both users might believe they can purchase the last item, leading to a race condition
where one user’s update is lost.

- Inconsistent Data: The final inventory count may be incorrect due to interleaved and uncontrolled
updates.

2. Using Transactions and Locks for Inventory Consistency:

- *Transactions: Implement a transaction for each user attempting to purchase the item. This
ensures atomicity, meaning the entire transaction (reserve and update inventory) either succeeds or
fails.

- *Locks: Use locks to ensure exclusive access to the inventory during the transaction. For example,
employ a write lock on the inventory when a user initiates the purchase transaction, preventing
other transactions from modifying the inventory concurrently.With proper transaction management
and locks, you can maintain consistency in the inventory, ensuring that only one user successfully
purchases the last item, and the inventory count is accurately updated.

You might also like