1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
static DWORD WINAPI Thread2(LPVOID end)
{
int i = 0, cpt = 0;
DWORD ret = 0;
while(!g_bEnd)
{
if (i++ == 50){
ret = WaitForSingleObject(g_hSema,WAIT_SEMA_TIME);
if (ret == WAIT_FAILED)
cout <<"Thread2: ERROR -> NUMBER " << GetLastError() <<"\n";
cout << "Nombre de 2: "<< cpt <<"\n";
if (!ReleaseSemaphore(g_hSema, 1, NULL))
std::cout << "Problème pour libérer la sémaphore...\n";
WaitForSingleObject(g_hEvent,INFINITE);
i = 0;
}
if (i == 25)
if (!PostThreadMessage(g_lpThreadId[3],1,0,0)){
cout << "Thread2: Probleme pour poster le message\n";
AfxError();
}
std::cout<<"2"; cpt++;
Sleep(200);
}
return g_bEnd;
}
static DWORD WINAPI Thread4(LPVOID end)
{
int i = 0, cpt = 0;
LPMSG lpMsg = NULL;
while(GetMessage(lpMsg,NULL,0,0)>0 || (g_bEnd))
{
if (lpMsg->hwnd == NULL)
{
cout << "Thread4 a recu le message: "<< "\n";
}
}
return g_bEnd;
}
static void AfxError (void)
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
0, // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
// Process any inserts in lpMsgBuf.
// ...
// Display the string.
AfxMessageBox((LPCTSTR)lpMsgBuf, MB_OK | MB_ICONINFORMATION );
// Free the buffer.
LocalFree( lpMsgBuf );
} |
Partager