On Feb 22, 2007, at 8:21 PM, Nathan Folkman wrote:
For John. Just curious as to what problem the "try lock" was needed
for.
I'm trying to block the "double submit" problem on web pages, where a
page submit takes too long (because something else is taking up the
server), so the user hits cancel and resubmits.
When the original taking-up-the-server code completes, now the two
submissions occur at exactly the same moment, and the submission is
processed twice. I currently use a database (check the database to
make sure this operation hasn't previously run) call to prevent this,
but if the two pages occur at the exact same moment, the database
call isn't atomic enough to prevent the double-submit.
I previously used a simple mutex to prevent the double-submit
problem, but would occasionally get a deadlock when deployed in the
field. The deadlock is probably due to some operations needing two
locks, and thus locking against each other, and is debuggable, but
with some work and with quite negative consequences on a live server,
since I have to shut down the server to unlock the jammed threads.
Instead, to solve the "double submit" problem, I planned a more
simple strategy:
1) try to grab a mutex, so I'm the only one doing this
2) if I can't grab a mutex, wait 1 second, and try again
3) after 5 seconds, give up on the mutex, and proceed anyway, since
if there is a double-submit, chances are the two threads aren't
running at the same moment any more. And, display an error, so that
the programmer can investigate and see if there is a deadlock-causing
bug in this code.
-john
--
AOLserver - http://www.aolserver.com/
To Remove yourself from this list, simply send an email to <[EMAIL PROTECTED]>
with the
body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject:
field of your email blank.