需要一个良好的解决方案用于同步读写 [英] need a good solution for synchronized read write

查看:106
本文介绍了需要一个良好的解决方案用于同步读写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个线程(WRITER),在输入数据到达时连续填充缓冲区(在我的例子中是一个向量)。
我有另一个线程(READER)定期检查缓冲区的输入数据,并清除缓冲区处理数据完成后。
一旦我看到一个实现,建议有两个缓冲区(A和B)。 WRITER写入缓冲区A,当它是读取数据的时间时,READER接管缓冲区A,并且WRITER开始读取B ...并且这种翻转继续。



我googled为参考或示例代码,但找不到任何。
你能建议我参考吗? / div>

最简单的解决方案是在Boost库的帮助下使用同步队列



on CodeProject 此处,以及Google上的无数示例。


I have a thread(WRITER) that continuously populates a buffer(a vector in my case) as the incoming data arrive. And i have another thread(READER) that periodically checks the buffer for incoming data and clears the buffer after processing data is done. Once I saw an implementation that suggested to have two buffers (A and B) instead. the WRITER writes into buffer A, and when it is the time for reading the data, the READER takes over buffer A and WRITER starts reading into B...and this flipping continues.

I googled for a reference or sample code but couldn't find any. Can you please suggest me a reference? Also, is this the best and simplest approach?

thank you

解决方案

The simplest solution is using a syncronized queue with the help of the Boost libraries.

There is an article about this on CodeProject here, and countless examples on Google.

这篇关于需要一个良好的解决方案用于同步读写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆