Вопрос

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?

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top