[Gllug] A programming question. long.
home at alexhudson.com
home at alexhudson.com
Thu Jul 5 13:03:57 UTC 2001
On Thu, Jul 05, 2001 at 04:59:23AM -0700, David Irvine wrote:
> so we need some sort of locking. Enter the spin lock.
Didn't look like a spinlock to me :) A spinlock is:
while ((stat_lock=lock())&&(time<timeout)) if (stat_lock) break;
if (stat_lock) {
// locked
} else {
// couldn't attain lock
}
Not recommended for any code anywhere except certain parts of the kernel.
You want a semaphore, courtesy of Djikstra. Certainly not a spinlock, and
certainly not in Perl. You could also use a filelock instead - designate a
file, and flock() it. Just make sure you know the difference between
advisory and mandatory locking.
> Now, heres the tricky bit we only want to lock the
> table, and we only really want it for select
> statements.
Why not use an SQL lock? Are you using a proper database? If so, it may also
have transactions, which are also useful. Even MySQL supports table locking.
Postgres will allow you to lock rows (IIRC - certainly, commercial dbs do),
which might be even more to your liking.
Cheers,
Alex.
--
--
Gllug mailing list - Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug
More information about the GLLUG
mailing list