Cooperative Locks

MySQL has other kinds of locking arrangements. You can use cooperative or advisory locks so that client threads can cooperate with one another.

Cooperative locks have nothing to do with table locks; they have no power to block access to tables, and have an effect only if all relevant applications look for the presence of an advisory lock before proceeding. That's why they're called cooperative.

You can even think of them as ways of passing information between different instances of an application, but using MySQL to convey the message.

Cooperative locks are implemented by the functions GET_LOCK() and RELEASE_LOCK(). Here's the syntax:

GET_LOCK(string,timeout)

RELEASE_LOCK(string)

GET_LOCK() attempts to gain a lock with the ...

Get Sams Teach Yourself MySQL in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.