如何在两个线程之间共享一个大的高速数据 [英] How share a big high speed data between two thread

查看:77
本文介绍了如何在两个线程之间共享一个大的高速数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我是绿手。现在我遇到了一个谜题。我需要收到然后不断发送char [2048]数组。

在我看来,接收和发送一个线程效率低下。所以我创建了两个线程发送和接收。我有多核,所以这两个线程可以并行运行。

现在我的问题是如何在两个线程之间共享char数组。首先,不应使用全局变量。我应该选择什么方式。然后应该使用缓冲区,即页面缓冲区。

你能给我一些建议吗?

解决方案

抱歉,你需要一个全局数据资源。这是避免复制数据的唯一可能性。您必须管理的访问权限,例如使用Mutex。您将找到一个示例这里

Hello, I'm a green hand. Now I meet a puzzle. I need received and then send a char[2048] array continually.
In my mind put receiving and sending in one thread inefficiency . So I create two threads sending and receiving. I have multicore so these two threads could parallel running.
Now my problem is how can I share the char array between two threads. First of all, the global variable shouldn't used. What's way should I choose. Then did the buffer should be used ie page buffer .
Could you give me some advice?

解决方案

Sorry but you need a global data resource. It is the only possibility to avoid copying data. The access you must manage, for instance with a Mutex. An example you will find here..


这篇关于如何在两个线程之间共享一个大的高速数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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