Out of Memory Error: MultiThreading Problem?
I have an application with various worker threads each performing
calculations on separate data sets specific to each thread and a dll
which processes remote server msgs. Each of these worker threads and
dll use a class called MessageMgr to notify the main dialog to update
specific list controls with the data derived from the calculations.
The main function in MessageMgr used to communicate with the dialog is
SendMsgToDlg where strMsg is the msg to insert into the control and
msgType indicating which control to update:
void MessageMgr::SendMsgToDlg(const char* strMsg, int msgType){
CString * s = new CString(strMsg);
pDlg->PostMessage( UWM_ADDSTRING, msgType, LPARAM(s));
}
The dialog then processes the msg and deletes the pointer.
I'm getting out of memory errors when two or more threads send
messages to the same control. It doesn't happen always, just when
there are many many msgs occurring. Before the memory error the GUI
freezes, and after the error it dumps all the messages into the list
box (about 2GB worth)... which all happen to be a repeat of a single
message, as if caught in an infinte loop. The repeat msgs are always
from the dll which process the server msgs.
Unfortunately, the dll is closed source to me, so I have no way of
knowing if it is the culprit. However, assuming it is NOT the problem,
is what I'm doing problematic in a multithreaded environment? I was
under the impression that PostMessage just queues up the msgs in
order received, so is essentially thread safe. The only thing that
leaves would be the pointer creation and deletion... should I be using
SendMessage in order to make sure the prior pointer was deleted before
creating a new one?
Bit confused and would really appreciate the help,
Marcus