Hi All,
I have a little problem with it comes to thread safe locking that I cannot seem to solve. The problem is that a thread has to own 2 locks on two different objects, it then needs to wait on one of them, but somehow before waiting, release the lock on the first.
This is basically a database problem, I have a lock manager that needs to perform it's locking in isolation, hence a synchronised method called lock. Once in the method if the record the thread is looking for is locked alread it needs to wait on the lock so that when the record is unlocked only threads waiting for that record are woken, not all threads waiting for all other records. To do this the thread needs to obtain the lock on the lock object. Therefore a synchonized block with in the lock method.
The trouble is, when the thread waits, it still holds the lock on the Lock Manager, which then causes deadlock...
I have been trying to solve this paradigm in a threadsafe way and have so far not come to much.
I am not sure the beast way of doing it. Maybe the way I am doing it is wrong, but I am not sure another way that is totally thread safe.
Any help or comments are very welcome...
Thank you for your help.
James.
I have a little problem with it comes to thread safe locking that I cannot seem to solve. The problem is that a thread has to own 2 locks on two different objects, it then needs to wait on one of them, but somehow before waiting, release the lock on the first.
This is basically a database problem, I have a lock manager that needs to perform it's locking in isolation, hence a synchronised method called lock. Once in the method if the record the thread is looking for is locked alread it needs to wait on the lock so that when the record is unlocked only threads waiting for that record are woken, not all threads waiting for all other records. To do this the thread needs to obtain the lock on the lock object. Therefore a synchonized block with in the lock method.
The trouble is, when the thread waits, it still holds the lock on the Lock Manager, which then causes deadlock...
I have been trying to solve this paradigm in a threadsafe way and have so far not come to much.
I am not sure the beast way of doing it. Maybe the way I am doing it is wrong, but I am not sure another way that is totally thread safe.
Any help or comments are very welcome...
Thank you for your help.
James.