Yup, MySQL works quite well as a lock server; we've been using it as such
for years.

I would suggest looking at the get_lock() function specifically.  It's
designed to do exactly what you're looking for, and it won't require
knowledge of any tables or rows.

Cheers.
-Dana

> -----Original Message-----
> From: Michael T. Babcock [SMTP:[EMAIL PROTECTED]]
> Sent: Friday, January 03, 2003 10:38 AM
> To:   [EMAIL PROTECTED]
> Subject:      Info: Using MySQL as Mutex
> 
> Just as an FYI to fellow developpers out there (feeling generous today):
> 
> How many times have you written a semaphore locking system for your 
> programs and worried they weren't thread-safe, or wished you didn't have 
> to?  Well, if you're feeling especially lazy (as I often do) and you 
> have MySQL on hand, try using its locking features instead of writing 
> your own (especially if your program already involves MySQL).  Connect 
> to MySQL [this assumes you're using InnoDB/BDB], do a BEGIN and try to 
> UPDATE a row in a locks table for your mutex (UPDATE Locks SET Holder = 
> "me" WHERE Name = "ThreadMutex4") and do your work.  MySQL will block 
> the UPDATE until the previous thread (if any) rolls back or commits its 
> transaction.
> 
> Any thoughts / technical comments? (I just started doing this in a large 
> internal log tracking project that does, in fact, use MySQL) :-)
> 
> -- 
> Michael T. Babcock
> C.T.O., FibreSpeed Ltd.
> http://www.fibrespeed.net/~mbabcock
> 
> 
> 
> ---------------------------------------------------------------------
> 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


**********************************************************************
This email and any files transmitted with it are confidential
and intended solely for the individual or entity to 
whom they are addressed.  If you have received this email
in error destroy it immediately.
**********************************************************************
             Wal-Mart Stores, Inc. Confidential
**********************************************************************


---------------------------------------------------------------------
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