XLL+ Class Library (6.3)

Ensuring global data is thread-safe

Multi-threaded Excel

One of the more exciting features of Excel 2007 is its ability to calculate on multiple threads at the same time. Excel's calculation engine locates areas of a workbook that have no dependencies on each other, and recalculates each area in isolation from the others, using as many threads as are available.

This is a very powerful improvement, particularly on machines with multi-cored processors or multiple processors.

Multi-threading is also particularly useful if you are passing calculations out to a grid-computing network, even on a machine with a single processor. All the threads that are waiting on the grid will be blocked, and will therefore impose virtually no processing cost. The threads that are calculating locally will have the full power of the CPU(s) to work with.

Thread-safe functions

You can mark your functions as thread-safe using the XLL+ Function Wizard:

Or you can use the Properties window:

Thread-safe global data

If your thread-safe function makes any use of global data then you must ensure that all access to the global data is thread-safe. If necessary, you can use the CXlLockable and CXlLock classes to synchronize access to global classes.

Next: Results cache >>