• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 12. Locking > Dealing with Deadlocks

Dealing with Deadlocks

One potential hazard of using <cflock> is that nested locks can lead to a deadlock. A deadlock occurs when two or more locks are initiated on separate templates. Say that you have two pages that lock both the APPLICATION and SESSION scope. The first page, named login.cfm, records a user's name in a SESSION variable and then appends the name to an APPLICATION variable. The APPLICATION variable contains an embedded structure of users who are currently logged in. A second page, logout.cfm, clears the SESSION structure and removes the user's name from the embedded structure in the APPLICATION scope.

These pages behave perfectly if the scopes are locked and nested in the same order. If, however, the locks are nested in a different order, the potential for a deadlock exists. The following code causes a deadlock:


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint