dan
dan

Reputation: 53

Thread safe associative container

I have a map which looks like this: std::map<int, class A*> m. I have two threads: one of them is reading m and updating the values of the object contained and the other one is reading and writing (removing elements). Is there a way to make it thread-safe without using mutexes?

Upvotes: 1

Views: 149

Answers (1)

Mike Seymour
Mike Seymour

Reputation: 254471

Is there a way to make it thread-safe without using mutexes?

No.

You might be able to write your own lock-free map, perhaps with ideas like this, or try third-party libraries like this, but the standard map gives no thread safety guarantees.

Upvotes: 4

Related Questions