문제

I'm trying to simulate that my two processes who executes in two different cpu enter the critical section. When both processes' instruction become "CS", I would like to send one of them to the blocked queue. However, even I give the sequence of instructions of two processes same and while they are working in different CPUs in parallel, they both enter the critical section in my simulation code. Can you please analyze my code and tell me what I am doing wrong?

void execute(CPU *cpu)
{
fetch(cpu);
while(cpu->instruction=="NI") {
    //printf("instruction : %s, instructionNo: %d, totalExecution in cpu:%d \n", cpu->instruction, cpu->instructionNo, cpu->totalExecuted);
    Sleep(1000);
    fetch(cpu);
}

if(cpu->instruction=="CS"){
    printf("process %d instruction no: %d",((PCB*) ((cpu->runningProcess)->dataPtr))->processID, cpu->instructionNo);
    WaitForSingleObject(csMutex, INFINITE);
        if(csBoolean==FALSE) {
            csBoolean==TRUE;
        }
        else if(csBoolean==TRUE) {
            printf("process %d suspended.",((PCB*) ((cpu->runningProcess)->dataPtr))->processID);
            ReleaseMutex(csMutex);
            contextSwitch(cpu);
            return;
        }
    ReleaseMutex(csMutex);

    printf("process %d entered its critical section.\n",((PCB*) ((cpu->runningProcess)->dataPtr))->processID);
    Sleep(3000);

    WaitForSingleObject(csMutex, INFINITE);
        csBoolean=FALSE;            
    ReleaseMutex(csMutex);

    ((PCB*)((cpu->runningProcess)->dataPtr))->instructionNo = cpu->instructionNo;
}

else if(cpu->instruction!="NI"){
    contextSwitch(cpu);
}
}
도움이 되었습니까?

해결책

Yep, stupid Visual Studio didn't want to bother me about this annoying syntax error:

 if(csBoolean==FALSE) 
  {
          csBoolean==TRUE;
  }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top