Skip to content

Thread Safety

Hannes Hauswedell edited this page Apr 28, 2017 · 2 revisions
  1. not thread-safe or unknown
  2. does not modify data (safe to be called from multiple threads, as long as no other functions modifies the data)
  3. modifies, but re-entrant (safe to be called from multiple threads, as long as the data is different – different parameters or member function on different object)
  4. thread-safe (always safe)

Some rules-of-thumb:

  • All const member functions should be 2 or 4.
  • All non-const member functions should be 3 or 4.
  • All free functions shall be 2 or 4 (if they take only copy or const & parameters) or 3 or 4 (otherwise)

Every function starts with 1., but should at least guarantee 2.

TODO: maybe rename to "data races"? Use other definitions?

Clone this wiki locally