How to implement a reader/writer lock in C++14

前端 未结 1 1106
情深已故
情深已故 2021-01-15 23:53

I have a hash table data structure that I wish to make thread safe by use of a reader/writer lock (my read:write ratio is likely somewhere in the region of 100:1).

I

相关标签:
1条回答
  • 2021-01-16 00:32

    C++14 has the read/writer lock implementation std::shared_timed_mutex.

    Side-note: C++17 added the simpler class std::shared_mutex, which you can use if you don't need the extra timing functions (like shared_timed_mutex::try_lock_for and shared_timed_mutex::try_lock_until).

    However, before using a read/writer lock, be aware of the potentially harmful performance implications. Depending on the situation, a simple std::mutex might be faster.

    0 讨论(0)
提交回复
热议问题