. . . .
GetModuleFileName(NULL,szFilename,MAX_PATH); TCHAR szCmdLine[MAX_PATH]; for ( i = 0; i < 3; i++) {
sprintf(szCmdLine,\,szFilename,i); STARTUPINFO si;
ZeroMemory(reinterpret_cast
bCreateOK=CreateProcess( szFilename, szCmdLine, NULL, NULL, FALSE,
CREATE_DEFAULT_ERROR_MODE, NULL, NULL, &si, &pi);
if (!bCreateOK) {
return false;
. . . .
. . . .
}
lpHandle[num]=pi.hProcess; num++; }
for ( i = 0; i < 2; i++) {
sprintf(szCmdLine,\,szFilename,i); STARTUPINFO si;
ZeroMemory(reinterpret_cast
bCreateOK=CreateProcess( szFilename, szCmdLine, NULL, NULL, FALSE,
CREATE_DEFAULT_ERROR_MODE, NULL, NULL, &si, &pi);
if (!bCreateOK)
. . . .
. . . .
{
return false; }
lpHandle[num]=pi.hProcess; num++; }
return true; }
void Parent() {
printf(\quit.\\n\);
hMutexMapping=CreateMutex(NULL,true,\); HANDLE hMapping=CreateFileMapping( NULL, NULL,
PAGE_READWRITE, 0,
sizeof(LONG), \);
if (hMapping!=INVALID_HANDLE_VALUE) {
. . . .
. . . .
LPVOID pData=MapViewOfFile( hMapping,
FILE_MAP_ALL_ACCESS, 0, 0, 0);
if (pData!=NULL) {
ZeroMemory(pData,sizeof(LONG)); }
struct buf *pnData=reinterpret_cast
memset(pnData->buffer,0,sizeof(pnData->buffer)); UnmapViewOfFile(pData); }
CreateSemaphore(NULL,3,3,\); CreateSemaphore(NULL,0,3,\); BOOL bCreateOK=StartClone(); if (!bCreateOK) {
. . . .
. . . .
//printf(\ } else {
//printf(\ }
ReleaseMutex(hMutexMapping); }
void Productor(int n) { int j;
printf(\);
hMutexMapping=OpenMutex(MUTEX_ALL_ACCESS,true,\); HANDLE hMapping=OpenFileMapping( FILE_MAP_ALL_ACCESS, NULL, \);
if (hMapping==INVALID_HANDLE_VALUE) {
printf(\); }
. . . .
相关推荐: