There is a server:
STARTUPINFO si; PROCESS_INFORMATION pi; DWORD dwExitCode; ZeroMemory(&si, sizeof(STARTUPINFO)); si.cb = sizeof(STARTUPINFO); if (!CreateProcess("C:\\Users\\Артем\\Documents\\visual studio 2015\\Projects\\Writer\\Debug\\Writer.exe", NULL, NULL, NULL, FALSE, NULL, NULL, NULL, &si, &pi)) { cout << GetLastError(); _getch(); return -1; } Sleep(10); cout << "Process 1: "; while (GetExitCodeProcess(pi.hProcess, &dwExitCode) != 0 && dwExitCode == STILL_ACTIVE) { WaitForSingleObject(hMutex, INFINITE); cout << *((LPSTR)lpFileMap); ReleaseMutex(hMutex); Sleep(100); } Which creates the client process and gets from FileMapping the character that was entered in the Client.
Customer:
WaitForSingleObject(hMutex, INFINITE); while (true) { chr = _getch(); if (chr == '1') { *((LPSTR)lpFileMap) = '+'; ReleaseMutex(hMutex); } if (chr == '2') { *((LPSTR)lpFileMap) = '-'; ReleaseMutex(hMutex); } if (chr == '3') { *((LPSTR)lpFileMap) = ' '; ReleaseMutex(hMutex); WaitForSingleObject(hMutex, INFINITE); while ((chr = _getch()) != '\r') { *((LPSTR)lpFileMap) = chr; ReleaseMutex(hMutex); WaitForSingleObject(hMutex, INFINITE); *((LPSTR)lpFileMap) = '\0'; } break; } Sleep(10); *((LPSTR)lpFileMap) = '\0'; if(chr > '0' && chr < '4') WaitForSingleObject(hMutex, INFINITE); } When entering 1, the + symbol is transmitted, when 2 is entered, the - symbol is displayed, and when 3 is entered, a message informs about the completion of the process.
Question: How can I start several identical client processes and synchronize them? For example, the user enters from the console the number of client processes, the server creates them, and in turn from each process receives a message. Those. The first process sent +, the server accepted and passed to the second, the second sent -, the server accepted and passed to the first and so on.