Is the C++ std::set thread-safe?

Viewed 39003

I've a question about the thread safety of std::set.

As far as I know I can iterate over a set and add/erase members and that doesn't invalidate the iterators.

But consider following scenario:

  • thread 'A' iterates over a set of shared_ptr<Type>
  • thread 'B' occasionally adds items to this set.

I've experienced segfaults as the program runs and I'm not sure why this happens. Is lack of thread safety the cause?

6 Answers
Related