Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Sunday, June 28, 2009

multi-threading std::map issue

class tagtree
{
...
public:
std::map mapControllee;
};

** working code **

tagtree *tt;
tagtree *ttController;
tt = AddNode(...);
ttController = tt;
tt = AddNode(...);
ttController->mapControlle[strName] = tt; <- crash in compare down to _tcmp lpsz 0xcdcdcdcd

http://www.dinkumware.com/vc_fixes.html[^]

Synchronization of multiple reader and writer processes using Mutex

void CServer::WriteToMemory()
{
mutex.Lock();
switch memory page
...
...
write something
...
...
mutex.Unlock();
}
void CServer::ReadFromMemory()
{
mutex.Lock();
get last writen memory page
mutex.Unlock();
...
...
read something
...
...
}