64,282
社区成员
发帖
与我相关
我的任务
分享
CcriticalSection g_cs;
线程1:写map
for(int i = 0; i < m_vectorSelectIndex.size(); i ++)
{
string str;
int nkey = m_vectorSelectIndex[i];
//dealwith str;
g_cs.lock()
m_mapFrameInfoValue[nkey] = str;
g_cs.unlock();
}
for (int i = 0; i < m_vectorSelectIndex.size(); i++)
{
string strValue = "";
int nKey = m_vectorSelectIndex[i];
strValue = GetMapFrameData(nKey);
if (strValue.empty())
{
strValue = "0";
}
WriteFile(strValue.c_str(), false); //把str写进文件
WriteFile(" ", false);
}
//令一个线程中
for (int i = 0; i < m_vectorSelectIndex.size(); i++)
{
string strValue = _T("");
int nKey = m_vectorSelectIndex[i];
strValue = GetMapFrameData(nKey);
if (strValue.empty())
{
continue;
}
m_pMyTest->m_pTestListCtrl->SetItemText(m_nRawIndexInListBox, i + 1, strValue.c_str());
}
//GetMapFrameData 的实现
string CDevice::GetMapFrameData(int nKey)
{
string strValue;
g_cs.Lock();
map<int, string>::iterator it = m_mapFrameInfoValue.find(nKey);
if (it == m_mapFrameInfoValue.end())
{
g_cs.Unlock();
return string("");
}
strValue = (*it).second;
g_cs.Unlock();
return strValue;
}
for(int i = 0; i < m_vectorSelectIndex.size(); i ++)
{
string str;
int nkey = m_vectorSelectIndex[i];
//dealwith str;
g_cs.lock()
m_mapFrameInfoValue[nkey] = str;
g_cs.unlock();
}
g_cs.lock();
for(int i = 0; i < m_vectorSelectIndex.size(); i ++)
{
string str;
int nkey = m_vectorSelectIndex[i];
//dealwith str;
//g_cs.lock()
m_mapFrameInfoValue[nkey] = str;
g_cs.unlock();
}
for(int i = 0; i < m_vectorSelectIndex.size(); i ++)
{
string str;
int nkey = m_vectorSelectIndex[i];
//dealwith str;
g_cs.lock()
m_mapFrameInfoValue[nkey] = str;
g_cs.unlock();
}
g_cs.lock();
for(int i = 0; i < m_vectorSelectIndex.size(); i ++)
{
string str;
int nkey = m_vectorSelectIndex[i];
//dealwith str;
//g_cs.lock()
m_mapFrameInfoValue[nkey] = str;
g_cs.unlock();
}