Write an algorithm for shared and exclusive locking. How does granularity affect this algorithm?
What will be an ideal response?
read_lock(X):
B: if LOCK (X) = "unlocked"
then begin
LOCK (X) = "readlocked";
noOfReads(X) = 1
end
else if LOCK(X) = "readlocked"
then noOfReads(X) = noOf Reads(X) + 1
else begin
wait (until LOCK (X) = "unlocked" and
the lock manager wakes up the transaction);
goto B
end
write_lock (X):
B: if LOCK (X) = "unlocked"
then LOCK (X) = "writelocked"
else begin
wait (until LOCK(X) = "unlocked" and
the lock manager wakes up the transaction);
goto B
end;
unlock_item (X):
if LOCK (X) = "writelocked"
then begin
LOCK (X) = "unlocked";
wakeup one of the waiting transactions, if any
end
else if LOCK(X) = "readlocked"
then begin
noOfReads(X) = noOfReads(X) 1;
if noOfReads(X) = 0
then begin
LOCK (X) = "unlocked";
wakeup one of the waiting transactions, if any
end;
end;
Algorithm 1 Locking and unlocking operations for twomode (readwrite or sharedexclusive)
locks
You might also like to view...
One way to bring a database into 3NF compliance is to delete all unnecessary fields
Indicate whether the statement is true or false
The ____ summary function estimates the standard deviation of all of the data to be summarized in a PivotTable report.
A. Sum B. Varp C. StdDev D. Product