Visit Sponsor

Written by 8:45 pm ColdFusion, Rapid Development

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:




“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 http://varscoper.riaforge.org/ . Thanks Mike and Zac for the fine work on one of the most important code checking tools out there!

Visited 22,303 times, 1 visit(s) today
[mc4wp_form id="5878"]
Close