8 Anti-pattern: thread-safe data types

Designing data types to be thread-safe (for example by having it contain its own mutex) is an anti-pattern.

This is because:

  • it increases complexity
  • making a data type thread-safe has a big space and performance overhead
  • data types tend to compose, for example using structs, tuples, relations, maps and arrays. Making part of a composite data type thread-safe isn't useful
  • Testing thread-safety is very difficult, it's better to avoid thread-safety promises in the first place