Showing posts from December, 2017

What is thread safety anyway?

Multithreading can be hard to do right. The most common point of failure is assuming some code is thread safe when it actually is not. And then the whole multithreading castle crumbles into ruins.

"Thread safe" is a pretty vague term. If you are not sure what it actually means, I suggest you start by reading Eric Lippert's blog post on the subject. On the other hand, if you do know what thread safety is, well, I suggest you read it anyway 🙂

What is this thing you call "thread safe"?

Wrong assumptions

When it comes to thread safety in Delphi (actually, this is not a Delphi-specific thing) there is very little built in by default. Basically, if you are writing some code that has to be thread safe, you have to take care of the thread safety part all by yourself. And you have to be very careful with your assumptions, as you can easily come to the wrong conclusions.

To demonstrate how deeply unsafety goes, and how easy is to make wrong assumptions, I will use ARC as…

Delphi Memory Management For Classic And ARC Compilers, eBook

Memory management. One of the most basic parts of software development, often kept on the side even though it has the most profound effect on how we write our code.

Delphi provides a variety of types with their own memory management logic, as well as two sets of compilers that provide different memory management systems for classes.

Classic Delphi compiler currently supported on Windows and OSX platforms - using manual memory management while providing ARC for certain types.Next generation ARC Delphi compiler supported on mobile Android and iOS platforms, as well as Linux - using full ARC - Automatic Reference Counting memory management system.
Each memory management system has its good and bad sides. Each offers solutions to some problems, but creates a whole range of other problems. And each requires slightly different coding patterns and practices. Knowing the strengths and weaknesses and understanding how memory management system(s) work goes hand-in-hand with writing clean, bug-fr…