Pas de dépendances
#include <windows.h> #include <stdio.h> #include <stdlib.h> HANDLE ghMutex; unsigned long WINAPI fonc1(void* params) { while(1) { //WaitForSingleObject(ghMutex,INFINITE); printf("message du thread "); Sleep(1); printf("numero 1\n"); //ReleaseMutex(ghMutex); } return 0; } unsigned long WINAPI fonc2(void* params) { while(1) { //WaitForSingleObject(ghMutex,INFINITE); printf("message du thread "); Sleep(1); printf("numero 2\n"); //ReleaseMutex(ghMutex); } return 0; } int main() { HANDLE h1; HANDLE h2; ghMutex = CreateMutex(NULL,FALSE,NULL); h1=CreateThread(NULL,0,fonc1,NULL,0,0); h2=CreateThread(NULL,0,fonc2,NULL,0,0); getchar(); CloseHandle(h1); CloseHandle(h2); CloseHandle(ghMutex); return 0; }
No explanations yet.