Read the KB article
http://www.allaire.com/Handlers/index.cfm?ID=20370&Method=Full

As for your code:

<cflock timeout="30" throwontimeout="Yes" type="EXCLUSIVE"
scope="SESSION">
<cfif NOT IsDefined("session.basket")>
<cfset session.basket = ArrayNew(2)>
</cfif>

<cfset FoundInBasket = 0>
<!--- Case 1 - Item already exists in basket - add qty --->
<cfif ArrayLen(session.basket) NEQ 0>
<cfloop from="1" to="#ArrayLen(session.basket)#" 
index="LoopCount">
<cfif session.basket[LoopCount][1] EQ "#Form.ModelNumber#"><cfset 
session.basket[LoopCount][3]=
session.basket[LoopCount][3]+#Form.AddQty#>
<cfset FoundInBasket = 1>
</cfif>
</cfloop>
</cfif>

<cfif NOT FoundInBasket>
<cfset 
session.basket[ArrayLen(session.basket)+1][1]=#Form.ModelNumber#>
<cfset session.basket[ArrayLen(session.basket)][2]=#Form.SalePrice#>
<cfset session.basket[ArrayLen(session.basket)][3]=#Form.AddQty#>
</cfif>
</CFLOCK>

-----Original Message-----
From: ehoma [mailto:[EMAIL PROTECTED]]
Sent: vrijdag 11 januari 2002 10:29
To: CF-Talk
Subject: Locking Session Variables?


Hi,

I'm new to using session variables and don't quite understand the
"locking"
thing.  What'll happen if you don't lock everything?

Here is some code that I've been using.  I used <cflock> when I created
the
array but not when I'm reading or writing.  It's been working fine.  Am
I in
for big bad application explosion?

How would you lock the code below?

Thanks,

Eric Homa


<CFLOCK TIMEOUT="30" THROWONTIMEOUT="Yes">
<cfif NOT IsDefined("session.basket")>
<cfset session.basket = ArrayNew(2)>
</cfif>
</CFLOCK>

<cfset FoundInBasket = 0>
<!--- Case 1 - Item already exists in basket - add qty --->
<cfif ArrayLen(session.basket) NEQ 0>
<cfloop from="1" to="#ArrayLen(session.basket)#" 
index="LoopCount">
<cfif session.basket[LoopCount][1] EQ "#Form.ModelNumber#"><cfset 
session.basket[LoopCount][3]=
session.basket[LoopCount][3]+#Form.AddQty#>
<cfset FoundInBasket = 1>
</cfif>
</cfloop>
</cfif>

<cfif NOT FoundInBasket>
<cfset 
session.basket[ArrayLen(session.basket)+1][1]=#Form.ModelNumber#>
<cfset session.basket[ArrayLen(session.basket)][2]=#Form.SalePrice#>
<cfset session.basket[ArrayLen(session.basket)][3]=#Form.AddQty#>
</cfif>


______________________________________________________________________
Get Your Own Dedicated Windows 2000 Server
  PIII 800 / 256 MB RAM / 40 GB HD / 20 GB MO/XFER
  Instant Activation � $99/Month � Free Setup
  http://www.pennyhost.com/redirect.cfm?adcode=coldfusionb
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to