Thread safe implementation of circular buffer

后端 未结 5 785
攒了一身酷
攒了一身酷 2020-11-29 02:25

Circular_buffer from boost library is not thread-safe. So I wrapped boost::circular_buffer object in a class as shown below. Mutual exclusion between the threads is achieved

5条回答
  •  情歌与酒
    2020-11-29 02:53

    Yes.
    If you lock all the public methods with the same lock it will be threadsafe.

    You could consider using read-write locks, which may have better performance if you have a lot of concurrent readers.

    If you don't have a lot of readers, it will just add overhead, but may be worth checking the option and testing.

提交回复
热议问题