Evniorment : Windows 7.0 , C++ , Multithreading
I have created a new worker thread to receive data on socket & add it into static multimap.
code snap :
//remember mymultimap is static data type
static std::multimap<string,string> mymultimap;
EnterCriticalSection(&m_criticalsection);
mymultimap.insert ( "aaa", "bbb") );
LeaveCriticalSection(&m_criticalsection);
At same time my main thread is reading same static multimap :
code snap :
EnterCriticalSection(&m_criticalsection);
std::multimap<string,string>::iterator it = mymultimap.begin();
for( ; it != mymultimap.end(); it++)
{
std::string firstName = (*it).first;
std::string secondName = (*it).second;
}
LeaveCriticalSection(&m_criticalsection);
As main thread & work thread are continously doing read & write, it hamper by my application peformance.
Also static multimap contains huge data (more than 10,000 records).
How I can make thread lock for minmiual time in multimap.
EnterCriticalSection(&m_criticalsection);
///minimal lock time for Map ???
LeaveCriticalSection(&m_criticalsection);
Please help me in improving application performance.