The question is simple: Why doesn't show up a message box? The operation ("do") startet in MyControllingFunction is lengthy. So all new threads are started in parallel. The mutexes are created in different threads, but should all refer to the same kernel object.
What point am I missing?
Thank's for any help. Christian
---------
UINT MyControllingFunction(LPVOID pParam )
{
CMyObject* pObject = (CMyObject*)pParam;
// Ensure exclusive execution
CMutex *oMttx = new CMutex(FALSE, "MUTEST");
CSingleLock singleLock(oMttx, FALSE);
if(singleLock.IsLocked()==TRUE){
AfxMessageBox("already in process!", MB_OK,0);
return 0;
}
else{
singleLock.Lock();
}
if (pObject == NULL ||
!pObject->IsKindOf(RUNTIME_CLASS(CMyObject)))
return 1; // if pObject is not valid
pObject->do();
return 0; // thread completed successfully
}
void CFormXYZ::OnBnClickedButton1()
{
CWinThread *cwt = AfxBeginThread(MyControllingFunction, &myObject);
cwt = AfxBeginThread(MyControllingFunction, &myObject);
cwt = AfxBeginThread(MyControllingFunction, &myObject);
cwt = AfxBeginThread(MyControllingFunction, &myObject);
cwt = AfxBeginThread(MyControllingFunction, &myObject);
}
What point am I missing?
Thank's for any help. Christian
---------
UINT MyControllingFunction(LPVOID pParam )
{
CMyObject* pObject = (CMyObject*)pParam;
// Ensure exclusive execution
CMutex *oMttx = new CMutex(FALSE, "MUTEST");
CSingleLock singleLock(oMttx, FALSE);
if(singleLock.IsLocked()==TRUE){
AfxMessageBox("already in process!", MB_OK,0);
return 0;
}
else{
singleLock.Lock();
}
if (pObject == NULL ||
!pObject->IsKindOf(RUNTIME_CLASS(CMyObject)))
return 1; // if pObject is not valid
pObject->do();
return 0; // thread completed successfully
}
void CFormXYZ::OnBnClickedButton1()
{
CWinThread *cwt = AfxBeginThread(MyControllingFunction, &myObject);
cwt = AfxBeginThread(MyControllingFunction, &myObject);
cwt = AfxBeginThread(MyControllingFunction, &myObject);
cwt = AfxBeginThread(MyControllingFunction, &myObject);
cwt = AfxBeginThread(MyControllingFunction, &myObject);
}