Select Page

Updating My Mental Model For Shared Array / Struct Iteration In ColdFusion

Published: June 23, 2022

In the very early days of ColdFusion, it was considered a “Best Practice” to synchronize access to all shared data structures. Meaning, to single-thread the access in order to avoid race conditions. Over time, this practice became much more nuanced; and, more of the native data types within ColdFusion became synchronized by default. Meaning, they were being made thread-safe internally. I believe that my mental model for iteration over shared data structures is outdated. As such, I wanted to run some parallel iterations in Adobe ColdFusion 2021 and Lucee CFML

To be clear, it was not so long ago (year 2018) that iteration over shared data structures has caused a problem: in Lucee CFML 5.2, iteration over shared arrays caused deadlocks in my application. But, as Zac Spitzer pointed out in the comments to that post, much as been done since then to make data access safer.

To explore the state of the modern ColdFusion engines, I’ll be using parallel array iteration to simulate concurrent access of the same data. Essentially, I’ll be trying to iterate over a shared value from different threads within the same request. I hope that this sufficiently exercises possible iteration contention.

CAUTION: Please note that I am iterating over read-only data. Attempting to iterative over data – either a Struct or an Array – that is mutated during iteration is still unsafe. With a Struct, it can cause “Concurrent Modification”; and, with an Array, it can cause “Undefined Value” errors. My interest in this post is only to iterate over shared, read-only data.

Check out the license.