Friday, December 30, 2005

Analogy

In the class today my faculty who teaches me java, gave an analogy for locking by threads while using shared resource. The concept is every thread must obtain a lock on a shared resource before using it and it should release it when the thread has performed it's task so as to avoid deadlock condition and phantom values read by other threads. In this way The example which he gave which was in turn given by his faculty goes like this… thread is you and shared resource is the toilet. You have to lock it from inside before you use it. In this way everybody will be able to use it without any conflicts. Be in a queue and wait for your turn. An excellent analogy to explain the concept. But still I feel just in case if a thread takes too long to finish off with the shared and locked resource other threads will have to wait till it finishes. It is fine with threads to use the resource whenever it is freed, but are we going to need the same resource like a toilet after waiting in a queue for so long?

No comments: