Skip to content

Commit

Permalink
Merge pull request #2 from notthemonkee/update-race-logic
Browse files Browse the repository at this point in the history
add missing NOT operator in race condition locking examples
  • Loading branch information
lmajano committed Aug 9, 2017
2 parents f6e185c + b6a7cf4 commit ec62789
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions coldfusion.md
Original file line number Diff line number Diff line change
Expand Up @@ -756,19 +756,19 @@ There will be cases where you need to do a double tests in order to avoid race c

```coldfusion
-- DO THIS --
<cfif structKeyExists(application,"controller")>
<cflock name="mainControllerCreation" timeout="20" throwOnTimeout="true" type="exclusive">
<cfif structKeyExists(application,"controller")>
<cfset application.controller = createObject("component","coldbox.MainController").init()>
</cfif>
</cflock>
<cfif not structKeyExists(application,"controller")>
<cflock name="mainControllerCreation" timeout="20" throwOnTimeout="true" type="exclusive">
<cfif not structKeyExists(application,"controller")>
<cfset application.controller = createObject("component","coldbox.MainController").init()>
</cfif>
</cflock>
</cfif>
-- NOT THIS --
<cfif structKeyExists(application,"controller")>
<cflock name="mainControllerCreation" timeout="20" throwOnTimeout="true" type="exclusive">
<cfset application.controller = createObject("component","coldbox.MainController").init()>
</cflock>
<cfif not structKeyExists(application,"controller")>
<cflock name="mainControllerCreation" timeout="20" throwOnTimeout="true" type="exclusive">
<cfset application.controller = createObject("component","coldbox.MainController").init()>
</cflock>
</cfif>
```
As you can see from the previous code snippet, if you do not have the double if statements, then code that is waiting on the lock, will re-execute the creation of the controller object. Therefore, since we can test the resource state, we can provide a multi-thread safety net.
Expand Down

0 comments on commit ec62789

Please sign in to comment.