Satsuma
a delicious .NET graph library
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Pages
Thread safety

A type is called thread safe if its instances can be simultaneously operated on by multiple threads without compromising integrity.

For example, a class is thread safe if its methods and properties behave correctly even if multiple threads call/access them at once.

The following rules apply for types defined in Satsuma, concerning thread safety:

The thread safety of an interface is in fact a restriction on implementor classes. In a sense, thread safety is part of the interface definition. For example, if ISomething is thread safe, then this means that all implementors should be written in a way that ISomething instances can be used by multiple threads at once.

Warning
If an interface or base class is thread safe, this does not imply that all implementor or descendant classes are thread safe. However, if an instance of the derived type is treated as an instance of the base type, then it should be thread safe. This statement may sound confusing, so let us take a fictional example.
  • Supposed that IReadOnlySomething is a thread safe interface.
  • WritableSomething, which implements IReadOnlySomething, may not be thread safe, as the data structure may be compromised if it is modified concurrently.
  • However, if only the IReadOnlySomething methods are called, then a WritableSomething instance should be freely usable by any number of threads.