How to make a multiple-read/single-write lock from more basic synchronization primitives?

后端 未结 8 757
[愿得一人]
[愿得一人] 2020-11-29 17:45

We have found that we have several spots in our code where concurrent reads of data protected by a mutex are rather common, while writes are rare. Our measurements seem to s

8条回答
  •  独厮守ぢ
    2020-11-29 17:56

    As always the best solution will depend on details. A read-write spin lock may be what you're looking for, but other approaches such as read-copy-update as suggested above might be a solution - though on an old embedded platform the extra memory used might be an issue. With rare writes I often arrange the work using a tasking system such that the writes can only occur when there are no reads from that data structure, but this is algorithm dependent.

提交回复
热议问题