I read from the documentation that the behavior of distributing a lock requested by many connections after RELEASE_LOCK
is called from the connection holding the lock is undefined. I was curious: say I have one procedure p1
which requests a lock with GET_LOCK("lock", 0);
so that multiple calls to this procedure don't interfere with each other. The procedure releases the lock before terminating. I have another procedure p2
which requests a lock using GET_LOCK("lock", 10);
.
Suppose there is a flood of calls to p1
, and somewhere in the middle, p2
is called, like this:
...
CALL p1();
CALL p1();
CALL p2();
CALL p1();
#lock released here from first p1() call: who gets it?
...
Theoretically, the second procedure shouldn't be affected much: it waits for the lock to be released and since GET_LOCK
in p1
has a timeout of 0, p2
should be the only one requesting the lock when it is released. However, I don't think I can expect this ideal behavior to be true. GET_LOCK
from the first procedure ends up taking some small but non-zero amount of time of course, and since the lock isn't assigned in order of request, is its possible for the lock to be passed down successive calls to p1
and p2
has to wait?