> -----Original Message-----
> From: S. Isaac Dealey [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, September 14, 2005 9:54 AM
> To: CF-Talk
> Subject: Re: Detecting CFLOCK
> 
> 
> I don't usually write locks that are designed to throw errors... I
> generally write locks that are designed to wait for the previous lock
> to release, and so I think my memory of how exactly the timeout works

I agree - I don't like to include exceptions as logic gates unless you
really, really need to.

A slight variation on this that would eliminate the need for the exception
is:

        <!--- Assume that the process is locked and set a marker variable to
that effect. --->
<cfset PDFProcessLocked = true />
<cflock name="makepdf" type="exclusive" timeout="1" throwontimeout="no">
        ... make the pdf ...
                <!--- When you're done with the process, set the marker
variable --->
        <cfset PDFProcessLocked = false />
</cflock>

        <!--- Check if the process is locked.  Since the LOCK is server-wide
but the marker variable is request specific this works even if somebody else
has since received the lock and is making a PDF --->
<cfif PDFProcessLocked >

        ... Whatever you do what somebody else is already making a PDF ...

<cfelse>

        ... Whatever you do when somebody is done making a PDF ...

</cfif>


Just to be clear: the marker variable is request-specific.  It lets you know
if the CURRENT REQUEST has been able to grab a hold of the lock.

The CFLOCK timeout and throwontimeout attributes are server-wide they'll
"know" if another template has the lock or not.  The timeout simply states
how long (in seconds) to wait for the lock to open up while the
throwontimeout says whether timing out waiting should be an error condition
or not.

In general required processes should throw an error and optional processes
(like this) probably shouldn't (since you can use code like I've shown to
react to the code's running or not).

It's not common that you see code like this, but it does happen.  One case
that I use it in a lot is Verity Reindexing.  I'll only let one reindex
occur at a time (even tho' two people have requested it).  Whoever gets
there second is told that a reindex is currently in process.

Jim Davis





~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Discover CFTicket - The leading ColdFusion Help Desk and Trouble 
Ticket application

http://www.houseoffusion.com/banners/view.cfm?bannerid=48

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:218220
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to