The added advantage here is that we can use the request variable as a substitute for the session variable over and over again, without the need for more locks. In fact, we can do so not only in the rest of the current template, but will also pass the request variable to the next page that we request from here. [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => BKBK [ip] => webforumsuser@m [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 7 [islastshown] => 1 [isfirstshown] => [attachments] => [allattachments] => ) --> To lock or not to lock? - Macromedia ColdFusion

To lock or not to lock? - Macromedia ColdFusion

Does this need a (readOnly) lock or not? Please kindly explain. <cfif isDefined("session.userLoggedIn") and session.userLoggedIn> <cfset x=5> <cfelse> <cfset x=3 </cfif>...

  1. #1

    Default To lock or not to lock?

    Does this need a (readOnly) lock or not? Please kindly
    explain.

    <cfif isDefined("session.userLoggedIn") and session.userLoggedIn>
    <cfset x=5>
    <cfelse>
    <cfset x=3
    </cfif>
    BKBK Guest

  2. #2

    Default Re: To lock or not to lock?

    erratum: please read <cfset x=3>

    BKBK Guest

  3. #3

    Default Re: To lock or not to lock?

    real nice discussion and links here:


    http://groups-beta.google.com/group/macromedia.coldfusion.advanced_techniques/br
    owse_thread/thread/1a7889619cf33e19/2bacc000304ed3a2?q=cold+fusion+variable+lock
    +best+practices&rnum=1&hl=en#2bacc000304ed3a2

    Especially read Ben's article.

    HTH,

    philh Guest

  4. #4

    Default Re: To lock or not to lock?

    Thanks for the links. I've read the messages and Ben Forta's
    article, but am none the wiser. My question is actually more
    of logic than of Coldfusion. This appears to be good CF code

    <cfif isDefined("session.userLoggedIn") and session.userLoggedIn>
    <cflock scope="session" timeout="20" type="exclusive">
    <cfset session.x=5>
    </cflock>
    </cfif>

    However, the condition, isDefined("session.userLoggedIn") and
    session.userLoggedIn,
    is itself a session variable. Should it therefore also be enclosed within
    cflock tags?
    I am asking whether the above code is, in fact, wrong, and the correct code
    should be

    <cflock scope="session" timeout="20" type="exclusive">
    <cfif isDefined("session.userLoggedIn") and session.userLoggedIn>
    <cflock scope="session" timeout="20" type="exclusive">
    <cfset session.x=5>
    </cflock>
    </cfif>
    </cflock>


    BKBK Guest

  5. #5

    Default Re: To lock or not to lock?

    Absolutely right. Any time you touch a session variable, you should enclose
    the action in a lock.

    Depending on what you need to do, you can set local variables equal to the
    session variables once at the beginning of the template.


    philh Guest

  6. #6

    Default Re: To lock or not to lock?

    philh wrote: 

    Actually you only really need to worry about locking session variables
    in the case of a possible race condition--this might provide some
    additional insight:
    http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=tn_18235

    Matt
    --
    Matt Woodward
    com
    Team Macromedia - ColdFusion
    mpwoodward Guest

  7. #7

    Default Re: To lock or not to lock?

    Like Philh, I do believe 'isDefined("session.userLoggedIn") and
    session.userLoggedIn'
    is a session variable that is being read. As such, it needs to be within a
    readonly lock.
    However, nested locks, whether readonly-and-exclusive or
    exclusive-and-exclusive can cause
    delays and deadlock. I have found a workaround myself. I wonder what the forum
    thinks of it.

    One solution is to put the isDefined, etc. condition within the lock. The
    cost is that we've placed an exclusive lock on a read-variable.

    <cflock scope="session" timeout="20" type="exclusive">
    <cfif isDefined("session.userLoggedIn") and session.userLoggedIn>
    <cfset session.x=5>
    </cfif>
    </cflock>

    A second solution, which I actually prefer, is to use the well-known
    trick of temporarily storing a variable of shared scope in a non-shared
    scope like 'variables' or 'request'. Thus, we get something along
    the lines of

    <!--- Any Code block that modifies the value of session.userLoggedIn, does
    precisely the same to
    request.userLoggedIn, for example --->
    <cfset session.userLoggedIn = true>
    <cfset request.userLoggedIn = "#session.userLoggedIn#">
    <!--- ------------------------------------------------------------------ --->

    <!--- Then, later on, we do --->
    <cfif IsDefined("request.userLoggedIn") and request.userLoggedIn>
    <cflock scope="session" timeout="20" type="Exclusive">
    <cfset session.x=5>
    </cflock>
    </cfif>

    The added advantage here is that we can use the request variable as a
    substitute
    for the session variable over and over again, without the need for more locks.
    In fact, we
    can do so not only in the rest of the current template, but will also pass the
    request
    variable to the next page that we request from here.



    BKBK Guest

Similar Threads

  1. How to lock pdf's??
    By Specialty_Pub@adobeforums.com in forum Adobe Acrobat Macintosh
    Replies: 1
    Last Post: November 10th, 08:52 PM
  2. NUM LOCK
    By Larry in forum Windows XP/2000/ME
    Replies: 3
    Last Post: July 25th, 01:55 PM
  3. Lock out
    By luds in forum Windows Setup, Administration & Security
    Replies: 0
    Last Post: July 24th, 11:42 PM
  4. NO Lock
    By Ray Hinton in forum Windows Setup, Administration & Security
    Replies: 0
    Last Post: July 17th, 01:10 PM
  5. lock down xp
    By Jay Simmons in forum Windows Setup, Administration & Security
    Replies: 4
    Last Post: July 7th, 01:47 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •