一个线程往另一个线程传数据的问题
我的代码大概是这样的:
struct SMSQUEUE
{
char pCallerNo[20];
char pCalledNo[20];
int type;
};
list<SMSQUEUE> g_MsgQueue;
定义全局对象g_MsgQueue,线程A往这个队列插入数据,线程B从这个队列读数据
线程A:
SMSQUEUE insSMS;
while(!bExit)
{
其他代码
g_MsgQueue.push_back(insSMS);
其他代码
}
线程B:
SMSQUEUE itMsg;
while(!bExit1)
{
其他代码
if(g_MsgQueue.empty())
continue;
itMsg=g_MsgQueue.front();
g_MsgQueue.pop_front();
其他代码
}
两个线程都在访问g_MsgQueue,会不会出问题???
是否需要加入LockCS之类的同步操作????或者cevent来做通知??