基于两个程序之间的事件触发器访问数据(内存)
Accessing data (memory) based on event trigger between two programs
这个问题对一些人来说可能很基本,但如果有人能在这里澄清我的疑虑,那就太好了。我有两个软件程序(两个进程),它们通过网络通过标准TCP连接进行通信。例如,程序A就像一个服务器,不断等待来自程序B的指令和数据。一旦程序A接收到数据,它就会立即将数据存储在向量数组中,并执行一个函数,该函数使用数组中的数据,并在最后将其清除。例如,在程序A内部:
std::vector<int> m_dataArray;
Run()
{
m_received = false;
while(1)
{
if(m_received)
{
Execution();
}
}
}
Listener(int data)
{
m_dataArray.push_back(data);
m_received = true;
}
Execution()
{
m_received = false;
// read from the data array and do something
m_dataArray.clear();
}
我的问题是,如果程序B一直向程序A发送数据,程序A是否会将所有这些传入数据放入缓冲区,直到程序A完成当前执行,然后再将新的数据集放入阵列?否则它将在访问内存的同时出现问题。(例如,即使程序A仍处于执行阶段,m_received标志是否会一直闪烁?)
如果这将成为一个问题,那么实施这样的措施以避免任何问题的最佳方式是什么?我想让程序A在发送下一个数据之前向程序B发出一个"完成"信号。
下面是一个例子,说明Run和Execution在执行时,侦听器可能会做什么,而不会有任何问题
std::vector<int> m_dataArray;
Run()
{
while(1)
{
if(m_dataArrayBuffer.length > 0)
{
// we take the data out and use it in execute
// these operations are independent of listener adding additional data
int data = m_dataArrayBuffer.pop();
Execution(data);
}
}
}
Listener(int data)
{
m_dataArrayBuffer.push_back(data);
}
Execution(int data)
{
// user the data and do something
}
相关文章:
- 用于访问容器<T>数据成员的正确 API
- 使用指针访问数组中的对象数据成员
- 友元函数无法访问私有数据成员 (c++)
- OpenCV C++ 3 维垫数据访问错误值
- 用于随机数据访问的最有效文件类型
- 用于多维数据访问的重载 () 运算符
- MEX C++原始数据访问
- C++数据访问基准
- 随机 mmaped 内存访问比堆数据访问慢 16%
- 共享内存多线程和数据访问
- 如何使用常见的C 业务逻辑和数据访问层构建跨平台移动应用程序
- 链表数据访问
- OpenMP线程、数据访问延迟和STL数据容器
- C++ 矢量数据访问
- 我很难在C++类中实现我想要的数据访问
- 概括模型中的数据访问.避免宏观的方法
- 矢量化/优化循环,用于宽寄存器(特别是Xeon Phi)的未对齐数据访问
- 松类耦合和数据访问
- 在Linux上锁定对单个进程内数据访问的最快方法
- 如何使用数据访问对象进行序列化和关系数据库数据访问