jeudi 31 janvier 2019

Is write-only to a shared std::unordered_map thread safe?

Say I have an initialized but empty std::unordered_map, and two simultaneous threads that are going to populate it. The two threads will only write to the map, and nothing will read from the map until the two threads are done.

Furthermore, the two threads will never operate on the same keys in the map. For example, say Thread 1 will populate keys "A" through "M", and Thread 2 will simultaneously populate keys "N" through "Z".

Is this thread safe?

In my current implementation, I have 8 threads writing to a single mutexed std::unordered_map in the fashion described above. The mutex obviously slows the process down (there are close to 10,000 keys being populated), so I'm wondering if I even need the mutex.

Thanks all!

Aucun commentaire:

Enregistrer un commentaire