raja singh kumar wrote:Suppose a thread which does not hold the monitor for an object calls a notifyAll() on that object. Say there are 99 other threads who are waiting for that monitor. Now out of the 99 threads one will get the monitor whereas the monitor may not be available since it was a false notifyAll(). So how is a false notifyAll() going to cause an issue?
And what do you mean by "false Notify()"?
Not sure where you are going with this? Are you trying to find a use case where it may not be a problem? ... and hence, conclude that it is not necessary? Remember the library needs to be useful (or it won't be used... ). I am sure you can dig up a use case where it may not cause a problem, but that doesn't mean that it is all that useful.
raja singh kumar wrote:By false notify(), I mean a thread not holding the monitor but calling notify() whereas the monitor for that object might be held by some other thread which may be currently using that object
raja singh kumar wrote:
And what do you mean by "false Notify()"?
By false notify(), I mean a thread not holding the monitor but calling notify() whereas the monitor for that object might be held by some other thread which may be currently using that object
raja singh kumar wrote:
Actually yes. Actually it would be utter chaos if threads not holding the lock call notify or wait. It would be unnecessary waste of CPU if threads keep calling wait and notify without holding the monitor. Never thought about the waste of CPU processing. Now I am clear.
And then we all jump out and yell "surprise! we got you this tiny ad!"
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|