I am trying to implement a simple advisory locking system for my application.
It is trying to mimic the functionality of a legacy inhouse database 
application, and the mysql GET_LOCK or LOCK TABLE does not seem sufficient 
for our purposes, as our application requires tables to be locked/unlocked, 
and for multiple locks to be active at any time.
(The GET_LOCK unlocks any previous locks before locking any new ones, which 
really screws with our code :-)  ).

Anyway,
My locking table will have the following format (or similiar),

CREATE TABLE mylocks
(
   lockname     char(20)   not null,
   pid           int        not null,
   status        int        not null,
   PRIMARY KEY (lockname)
);

When our application needs to "lock" a table, it will populate a row with the 
status set to "1" and the pid set to the thread connection id.

When our application sees that a lockname is "locked", it needs to also 
verify that the connection id is still valid. (i.e. that the process did not 
crash with "locks" active). 

This is the bit that has stumped me.

I originally was just going to do a "show processlist", but I've just read in 
the manual that this does not necessarily show all processes (depending on 
the current users grant table).

My questions:
1. Is there any way to check the "pid" (connection id) to see if it is still 
alive? (I dont want any information about it, just whether it's still 
connected).
2. has anyone already implemented such an advisory locking system? (rather 
than reinventing the wheel).
3. Is what I am trying to do just plain dumb! 

Many regards,
Ian Collins.
System Manager
KIWIPLAN NZ Ltd.

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to