Memory allocation in a parallel world
We’ve seen how FastMM4 boosts reallocation speed. Let’s take a look at another optimization that helps a lot when you write multithreaded code—as we will in the next three chapters.
The life of a memory manager is simple when there is only one thread of execution inside a program. When the memory manager is dealing out the memory, it can be perfectly safe in the knowledge that nothing can interrupt it in this work.
When we deal with parallel processing, however, multiple paths of execution simultaneously execute the same program and work on the same data. (We call them threads, and I’ll explain them in the next chapter.) Because of that, life from the memory manager’s perspective suddenly becomes very dangerous.
For example, let’s assume that one thread wants some memory. The memory manager finds a free memory block on a free list and prepares to return it. At that moment, however, another thread...