Is your code Thread Safe? How do you know?

Code that is not Thread Safe is sneaky, dangerous and leads to bewildering production errors and strange side effects.

As part of my deployment procedure, I run code through an automated code analyzer for improperly scoped variables. Today, while running the analyzer, it flagged this set of code:

view plain print about
1<cfset var ExistingRiskValuesList = "" />    
2<cfset ExistingRiskValueList = valuelist( RiskAssessmentQuery.TotalLeaseRisk ) >

"Wait just a minute", I said, "There is nothing wrong with that bit of code". Upon closer inspection I noted the 's' and quickly made the correction. Had I not used the automated code analyzer, this Thread-Unsafe code would have went into production.

There are many good posts about var scoping your variables, should you need more convincing. Mike Schierberl actually made and posted a video showing a memory leak in action caused by code that is not thread safe and Mike also gives away the automated code analyzer. If you haven't yet, I challenge you to download it and run it against some code. You might be surprised!

Update: Mike Schieberl and Zac Spitzer have made some improvements to the Var Scoper tool. The tool parses cfscript and is now hosted on . Thanks Mike and Zac for the fine work on one of the most important code checking tools out there!

There are no comments for this entry.

Add Comment Subscribe to Comments