rbadea_a
August 10th, 2005, 08:43 AM
Hello,
I have the following questions:
Please explain in more detail the following quote from msdn:
Windows Handle Maps
As a general rule, a thread can access only MFC objects that it created.
This is because temporary and permanent Windows handle maps are kept in thread local storage to ensure protection from simultaneous access from multiple threads. For example, a worker thread cannot perform a calculation and then call a document's UpdateAllViews member function to have the windows that contain views on the new data modified. This will have no effect at all, because the map from CWnd objects to HWNDs is local to the primary thread. This means that one thread may have a mapping from a Windows handle to a C++ object, but another thread may map that same handle to a different C++ object. Changes made in one thread would not be reflected in the other.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_multithreading.3a_.programming_tips.asp
Is the text above referencing ONLY MFC classes with handles, like CWnd ,CSocket, etc. (as specified in Technical Note 3 from the msdn VC++ documentation) or ALL MFC classes or ANY class (which I don't think) ?
What I mean is the following:
If I define a class of my own, CMyClass, which is not derived from any MFC class, can I pass a pointer to it in the call of AfxBeginThread ? Also, if the
object "CMyClass m_myObject" is declared as a member of a CWnd derived class in the main app thread, let's say CMyDialog (not on the heap), could there be some problems by passing this object to a worker thread? (Assuming of course the life time of the object is not an issue, destroyed when the app finished).
Example:
BOOL CMyDialogApp ::InitInstance()
{
if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
return FALSE;
}
AfxEnableControlContainer();
CMyDialog dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
}
else if (nResponse == IDCANCEL)
{
}
return FALSE;
}
Can a thread access also the stack of another thread? (Is passing a pointer to a stack object of another thread possible, again, presuming the lifetime of the stack object is not an issue) ?
Thank you .
I have the following questions:
Please explain in more detail the following quote from msdn:
Windows Handle Maps
As a general rule, a thread can access only MFC objects that it created.
This is because temporary and permanent Windows handle maps are kept in thread local storage to ensure protection from simultaneous access from multiple threads. For example, a worker thread cannot perform a calculation and then call a document's UpdateAllViews member function to have the windows that contain views on the new data modified. This will have no effect at all, because the map from CWnd objects to HWNDs is local to the primary thread. This means that one thread may have a mapping from a Windows handle to a C++ object, but another thread may map that same handle to a different C++ object. Changes made in one thread would not be reflected in the other.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_multithreading.3a_.programming_tips.asp
Is the text above referencing ONLY MFC classes with handles, like CWnd ,CSocket, etc. (as specified in Technical Note 3 from the msdn VC++ documentation) or ALL MFC classes or ANY class (which I don't think) ?
What I mean is the following:
If I define a class of my own, CMyClass, which is not derived from any MFC class, can I pass a pointer to it in the call of AfxBeginThread ? Also, if the
object "CMyClass m_myObject" is declared as a member of a CWnd derived class in the main app thread, let's say CMyDialog (not on the heap), could there be some problems by passing this object to a worker thread? (Assuming of course the life time of the object is not an issue, destroyed when the app finished).
Example:
BOOL CMyDialogApp ::InitInstance()
{
if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
return FALSE;
}
AfxEnableControlContainer();
CMyDialog dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
}
else if (nResponse == IDCANCEL)
{
}
return FALSE;
}
Can a thread access also the stack of another thread? (Is passing a pointer to a stack object of another thread possible, again, presuming the lifetime of the stack object is not an issue) ?
Thank you .