MySQL get_lock('test_lock', 0) always returns 1

Craig Smith :

As I understand it, get_lock('test_lock', 0) should return 1, or success, after the first call. A second call should return 0. After a release_lock('test_lock') is called, it would return 1 again. Is that right? I'm just using MySQL Workbench to run the commands and getting back a 1 each time. I was hoping to use this lock as a semaphore in my application.

Mureinik :

Once you successfully call get_lock, your session owns it, so subsequent calls from the same session will also succeed (and return 1). If you run get_lock and then open another MySQL Workbench session (e.g., by launching another instance of the application) and try to obtain the same lock, it will fail (and return 0).

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=298074&siteId=1