views:

36

answers:

1

Given the following scenario, I would like to know if functionOneLock releases itself before functionTwoLock is triggered, or does it wait until functionTwoLock releases first?

<!--- functionOne() --->
<cffunction name="functionOne">
<cflock name="functionOneLock" type="exclusive">
   <!--- do something --->
   <cfset functionTwo()>
</cflock>
</cffunction>

<!--- functionTwo() --->
<cffunction name="functionTwo">
<cflock name="functionTwoLock" type="exclusive">
   <!--- do something here --->
</cflock>
</cffunction>
+2  A: 

I presume you are calling functionOne() from functionTwo(), like so:

<!--- functionOne() --->
<cffunction name="functionOne">
<cflock name="functionOneLock" type="exclusive">
   <!--- do something --->
   <cfset functionTwo() />
</cflock>
</cffunction>

Since you are using named locks, your thread of execution will enter functionOneLock then within that call the other function thus entering functionTwoLock. It will then complete the code within that lock before returning from that function and completing functionOneLock.

So to answer your question functionOneLock will have to wait for functionTwoLock to complete.

Hope that helps.

Ciaran Archer
Ciaran, a small question, is there a way to trigger the second function but not wait for it to complete? Would I have to include the <cfset functionTwo()> in a <cfthread> tag?
Mel
Yes, if you use multi-threading you can do this. You can use `cfthread` to kick off a thread and the calling code will not wait for that thread, it is a totally separate process. If you do this just keep an eye on your thread settings in CF admin!
Ciaran Archer