Hi,

If a script using DB_File::Lock is interrupted by the STOP button, the file
will be appropriately unlocked.

When using DB_File::Lock, there really is no "critical section" for making
sure that the lock will be released appropriately. If a fatal exception
happens while the database is open, the lock will be released when the perl
garbage collector removes the tied variable. When this variable is cleaned
up and "untied", DB_File::Lock catches the untie call and removes the lock
while also closing the database in the correct order.

This is why DB_File::Lock exists: to catch this case. If the locking was
done like this:

Gain_lock()
Open_database()
.... Use database ....
Close_database()
Loose_lock()

Then there would be a "critical" section where if the code was interrupted
by the STOP button or a die() exception, the user wouldn't be guaranteed
that the database and/or lock would be closed and what order that would
happen.

If you are using DB_File::Lock, the code running while the database is open
is still "critical" in another sense: other processes are prevented from
getting locks they may desire. So, it's important to make sure that your
code doesn't do any unnecessary time-consuming processing while the database
is open.

David

-----Original Message-----
From: Dave Edsall - The Tauminator [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 16, 2001 3:47 PM
To: [EMAIL PROTECTED]
Subject: DB_File::Lock and the STOP button



   I have a question about DB_File::Lock with a database and users hitting
the STOP button. We have recently converted a database from an ASCII flat
file to db file. The ASCII flat file used flock() to lock the files. Now
that we have switched to DB_File, we have adopted DB_File::Lock as our
locking mechanism What we have essentially is:

      my($strDBFilename) = "msglist.db";
      my($locking)="write";
      tie(%msglistdb, 'DB_File::Lock', $strDBFilename,O_CREAT|O_RDWR,
0644,$DB_HASH,$locking)

      [...critical stuff...]

      untie(%msglistdb);

  If everything goes normally, this will provide a locked fence file that
will be unlocked when the file is closed during the untie. If I have read
the mod_perl guide correctly, when a user hits the STOP button on a
browser while the "critical stuff" is being processed, the script will
abort and the files will be closed and the fence file unlocked because we
magically go out of scope at the point of the abort. Is this a correct
reading? Will the lock be removed when the user hits the STOP button? If
so, for my own erudition, can someone explain to me why we go out of
scope in this case and why/how the files are closed when we go out of scope?


   Thanks in advance,


      Dave

Reply via email to