Using Mutex to prevent reentry
char mutexName[20]; sprintf(mutexName,"mutex%d",port); *hMutex = CreateMutexA(NULL, TRUE, mutexName); //printf("%d\n", *hMutex ); if (*hMutex == NULL) { //printf("Error creating mutex.\n"); return 0; } if (GetLastError() == ERROR_ALREADY_EXISTS) { //printf("The mutex alread exists.\n"); return 0; }ReleaseMutex(hMutex); CloseHandle(hMutex);
Last updated