Originally posted by Andras Nemeth:
Hi,
I checked my locks many times and always doubt in them a little.
Originally posted by Andras Nemeth:
No one try to reassure me that I do not need to develop fool proof locking?
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
Originally posted by Peter den Haan:
For this reason, my database lock would simply wait until all locks on the database had gone, then lock it. In the mean time, clients can freely acquire and release locks. That way, deadlocks can be avoided, at the price of having to wait longer for a database lock - but given the likely uses for a database lock (maintenance tasks &c) that is probably acceptable.
It has the added benefit of simplifying the logic considerably. If the client owns a database lock, record lock/unlock calls can simply be ignored. If not, you wait until ((the record you need has no lock or the lock is owned by you) and there is no database lock).
- Peter[/B]
In my implementation, client 2 would wait until no locks were remaining, excepting locks it held itself. So right after unlock(1), the client 2 thread would wake up (notifyAll()) and go through the lock map looking for locks held by other clients. There would be no such locks remaining. At that moment the database lock is granted.Originally posted by Andras Nemeth:
client 1: lock(1)
client 2: lock(3)
client 2: lock(-1) (wait)
client 1: unlock(1)
deadlock??? (client 2 wait, but can not release record 3)
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
Originally posted by Peter den Haan:
[B] [CODE]
public void lock(int recno) {
if (recno == DATABASE_LOCK) {
lockDatabase();
Thanks for the details. However now this has created little confusion. In my assignment I do not read any where to implement database lock. Is it a 'standard' which one needs to assume or is it specified (in some other words) in the assignment which I am overlooking.
Please clarify.
(I assume that your databse lock caters to administrator of server who may need it at the time of shutdown or maintenance).
regards.
Never be satisfied with anything less than the best and you will surely pass the test...
Never be satisfied with anything less than the best and you will surely pass the test...
Consider Paul's rocket mass heater. |