Bug #4137 get_lock does not work
Submitted: 15 Jun 2004 5:43 Modified: 16 Jun 2004 11:35
Reporter: Denis Koykov kdvik Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:4.0 OS:Any (ALL)
Assigned to: CPU Architecture:Any

[15 Jun 2004 5:43] Denis Koykov kdvik
Description:
1)bug
Tries to obtain a lock with a name given by the string str, with a timeout of timeout seconds. Returns 1 if the lock was obtained successfully, 0 if the attempt timed out (for example, because another client has already locked the name), or NULL if an error occurred (such as running out of memory or the thread was killed with mysqladmin kill).

select get_lock('list',100);
->1  
immediately we cause once again(сразу вызываем еще раз)
select get_lock('list',100);
->1  
on documentation
->0

2) bug
select get_lock('list',100) ;  /*timeout 100 seconds*/
after 1 second
IS_FREE_LOCK('list');
->1
on documentation
->0
   

How to repeat:
1)bug
Tries to obtain a lock with a name given by the string str, with a timeout of timeout seconds. Returns 1 if the lock was obtained successfully, 0 if the attempt timed out (for example, because another client has already locked the name), or NULL if an error occurred (such as running out of memory or the thread was killed with mysqladmin kill).

select get_lock('list',100);
->1  
immediately we cause once again(сразу вызываем еще раз)
select get_lock('list',100);
->1  
on documentation
->0

2) bug
select get_lock('list',100) ;  /*timeout 100 seconds*/
after 1 second
IS_FREE_LOCK('list');
->1
on documentation
->0
[15 Jun 2004 21:02] Philip
are you using hte same session?
try to open to independent connections and obtain the same lock in both of them
[16 Jun 2004 11:30] Hartmut Holzgraefe
This is expected behavior as locks are taken per session/connection.

A GET_LOCK(...) to a lock already held by a session will always 
succeed and you will get again what you already have.

The same is true for IS_LOCK_FREE(...), although its name is a
bit misleading here. IS_LOCK_FREE tests if you are able to
take a lock using GET_LOCK(...) without delay (unless someone 
would isse a GET_LOCK(...) inbetween your IS_LOCK_FREE and
GET_LOCK calls).

AFAIR i originaly suggested the name WOULD_LOCK_SUCCEED for
this function.