GET_LOCK(string,timeout)

Description: Attempts to gain an advisory lock with the name given by string, with a timeout given in seconds by timeout. Returns 1 if attempt is successful, 0 if a timeout occurs, or NULL if an error occurs.

GET_LOCK() is meant for use in conjunction with RELEASE_LOCK() to perform advisory or cooperative locking (that is, applications must cooperate with each other). Importantly, these functions do not perform table or row locking, such as the LOCK TABLES command does. They are intended for use in applications that cooperate by using an agreed-on lock name.

A lock is released when the thread finishes, another GET_LOCK() is issued, or a RELEASE_LOCK() is issued.

To see whether a lock is in place without waiting, GET_LOCK(string,0) may be used. This obtains the lock if it is not currently in force, so may have to be released using RELEASE_LOCK(string) if appropriate.

Example (commands run in sequence):

  • GET_LOCK("my_lock",5) by thread 1 returns 1 (lock obtained successfully).

  • GET_LOCK("my_lock",0) by thread 2 returns 0 immediately (unable to obtain lock at this time).

  • RELEASE_LOCK("my_lock") by thread 1 returns 1 (lock released successfully).

  • GET_LOCK("my_lock",0) by thread 2 returns 0 immediately (lock obtained successfully).

See also: RELEASE_LOCK(), LOCK TABLES (see Appendix B, “SQL Reference”)

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.103.204