📄 osdlg.cpp
字号:
pStat[i]->GetDlgItem(300+i);
pStat[i]->ShowWindow(SW_HIDE);
}
for(int countjc=0; countjc<pn; countjc++)
{
for(int j=0;j<3;j++)
{
pro[countjc][j]->GetDlgItem(211+3*countjc+j);
pro[countjc][j]->GetWindowText(tp[j]);
//delete pro[countjc][j];
pro[countjc][j]->ShowWindow(SW_HIDE);
}
newthread[countjc].threadname=tp[0];
newthread[countjc].timearrive=atoi(tp[1]);
newthread[countjc].timeneed=atoi(tp[2]);
newthread[countjc].timerun=0;
rear=(rear+1)%(pn+1);
}
pStat1 = (CStatic *)GetDlgItem(IDC_READY1);
pStat1->ShowWindow(SW_SHOW);
pStat1 = (CStatic *)GetDlgItem(IDC_READY2);
pStat1->ShowWindow(SW_SHOW);
pStat1 = (CStatic *)GetDlgItem(IDC_OVER1);
pStat1->ShowWindow(SW_SHOW);
pStat1 = (CStatic *)GetDlgItem(IDC_OVER2);
pStat1->ShowWindow(SW_SHOW);
}
//开始运行处理程序
void COSDlg::OnBnClickedButton4()
{
int thisway;
int timeout=0;
int stat=0;
int m;
Mythread temp;
CString tpp,tppjx,tppwc,test,tmp[20];
CStatic *pStatTimeout;
pStatTimeout = (CStatic *)GetDlgItem(IDC_RUNOUT);
//是按钮无效
CButton *pButton4 = (CButton *)GetDlgItem(IDC_BUTTON4);
pButton4->EnableWindow(0);
//将进程按到达时间排序
for (int countjc=1; countjc<pn; countjc++)
{
temp=newthread[countjc];
m = countjc-1;
while (m>=0&&temp.timearrive<newthread[m].timearrive)
{
newthread[m+1]=newthread[m];
m--;
}
newthread[m+1]=temp;
}
//处理进程调度情况
while(front!=rear)
{
pMythread=&newthread[stat%pn];
//该进程未运行完且已到达
if((pMythread->timerun<pMythread->timeneed)&&(pMythread->timearrive<=timeout))
{
//进程调度情况(进程剩余运行时间小于或等于时间片大小)
if((pMythread->timeneed-pMythread->timerun)<=slice)
{
while(pMythread->timeneed-pMythread->timerun>0)
{
//显示就绪队列
tppjx="";
for (int countjc=0;countjc<pn;countjc++)
{
if ((newthread[(stat+countjc)%pn].timearrive<=timeout)&&(newthread[(stat+countjc)%pn].timerun<newthread[(stat+countjc)%pn].timeneed))
{
tmp[0].Format("%d",newthread[(stat+countjc)%pn].timearrive);
tmp[1].Format("%d",newthread[(stat+countjc)%pn].timeneed);
tmp[2].Format("%d",newthread[(stat+countjc)%pn].timerun);
tppjx+="进程名:"+newthread[(stat+countjc)%pn].threadname+" 到达时间:"+tmp[0]+" 需cpu运行时间:"+tmp[1]+" 已运行时间:"+tmp[2]+"\n";
}
}
pStat1 = (CStatic *)GetDlgItem(IDC_READY2);
pStat1->SetWindowText(tppjx);
//显示当前调用进程
pStat1 = (CStatic *)GetDlgItem(IDC_CPUDO);
pStat1->SetWindowText(pMythread->threadname);
//显示当前已逝去时间
tpp.Format("%d",timeout);
pStatTimeout->SetWindowText(tpp);
timeout=timeout+1;
pMythread->timeover=timeout;
pMythread->timerun++;
Sleep(1000);
//显示完成队列
tppwc="";
for (int countjc=0;countjc<pn;countjc++)
{
if(newthread[(stat+1+countjc)%pn].timerun==newthread[(stat+1+countjc)%pn].timeneed)
{
tmp[0].Format("%d",newthread[(stat+1+countjc)%pn].timearrive);
tmp[1].Format("%d",newthread[(stat+1+countjc)%pn].timeneed);
tmp[2].Format("%d",newthread[(stat+1+countjc)%pn].timeover);
tppwc+="进程名:"+newthread[(stat+1+countjc)%pn].threadname+" 到达时间:"+tmp[0]+" 需cpu运行时间:"+tmp[1]+" 结束时刻:"+tmp[2]+"\n";
}
}
pStat1 = (CStatic *)GetDlgItem(IDC_OVER2);
pStat1->SetWindowText(tppwc);
}
front=(front+1)%(pn+1);
stat=(stat+1)%pn;
}
//进程调度情况(进程剩余运行时间大于时间片大小)
else
{
thisway=slice;
if(pMythread->timeneed-pMythread->timerun>0)
{while(thisway>0)
{
//显示就绪队列
tppjx="";
for (int countjc=0;countjc<pn;countjc++)
{
if ((newthread[(stat+countjc)%pn].timearrive<=timeout)&&(newthread[(stat+countjc)%pn].timerun<newthread[(stat+countjc)%pn].timeneed))
{
tmp[0].Format("%d",newthread[(stat+countjc)%pn].timearrive);
tmp[1].Format("%d",newthread[(stat+countjc)%pn].timeneed);
tmp[2].Format("%d",newthread[(stat+countjc)%pn].timerun);
tppjx+="进程名:"+newthread[(stat+countjc)%pn].threadname+" 到达时间:"+tmp[0]+" 需cpu运行时间:"+tmp[1]+" 已运行时间:"+tmp[2]+"\n";
}
}
pStat1 = (CStatic *)GetDlgItem(IDC_READY2);
pStat1->SetWindowText(tppjx);
//显示当前调用进程
pStat1 = (CStatic *)GetDlgItem(IDC_CPUDO);
pStat1->SetWindowText(pMythread->threadname);
//显示当前已逝去时间
tpp.Format("%d",timeout);
pStatTimeout->SetWindowText(tpp);
timeout=timeout+1;
thisway--;
pMythread->timerun++;
Sleep(1000);
}
}
//将当前队列送到就绪队列的队尾
temp=newthread[stat%pn];
for (m=0;m<pn-1;m++)
{
if((newthread[(stat+m+1)%pn].timearrive<=timeout)&&(newthread[(stat+m+1)%pn].timerun<newthread[(stat+m+1)%pn].timeneed))
{
newthread[(stat+m)%pn]=newthread[(stat+m+1)%pn];
}
else break;
}
newthread[(stat+m)%pn]=temp;
}
}
//该进程运行完了
else
{
if(pMythread->timearrive>timeout)
{
for (int countjc=0;countjc<pn;countjc++)
{
if ((newthread[(stat+countjc)%pn].timearrive<timeout)&&(newthread[(stat+countjc)%pn].timerun<newthread[(stat+countjc)%pn].timeneed))
goto Next;
else
continue;
}
//显示就绪队列
tppjx="";
for (int countjc=0;countjc<pn;countjc++)
{
if ((newthread[(stat+countjc)%pn].timearrive<=timeout)&&(newthread[(stat+countjc)%pn].timerun<newthread[(stat+countjc)%pn].timeneed))
{
tmp[0].Format("%d",newthread[(stat+countjc)%pn].timearrive);
tmp[1].Format("%d",newthread[(stat+countjc)%pn].timeneed);
tmp[2].Format("%d",newthread[(stat+countjc)%pn].timerun);
tppjx+="进程名:"+newthread[(stat+countjc)%pn].threadname+" 到达时间:"+tmp[0]+" 需cpu运行时间:"+tmp[1]+" 已运行时间:"+tmp[2]+"\n";
}
}
pStat1 = (CStatic *)GetDlgItem(IDC_READY2);
pStat1->SetWindowText(tppjx);
Sleep(1000);
//显示当前调用进程
pStat1 = (CStatic *)GetDlgItem(IDC_CPUDO);
pStat1->SetWindowText("空闲");
//显示当前已逝去时间
tpp.Format("%d",timeout);
pStatTimeout->SetWindowText(tpp);
timeout=timeout+1;
}
Next: front=(front+1)%(pn+1);
rear=(rear+1)%(pn+1);
stat=(stat+1)%pn;
}
}
//显示就绪队列
tppjx="";
for (int countjc=0;countjc<pn;countjc++)
{
if ((newthread[(stat+countjc)%pn].timearrive<=timeout)&&(newthread[(stat+countjc)%pn].timerun<newthread[(stat+countjc)%pn].timeneed))
{
tmp[0].Format("%d",newthread[(stat+countjc)%pn].timearrive);
tmp[1].Format("%d",newthread[(stat+countjc)%pn].timeneed);
tmp[2].Format("%d",newthread[(stat+countjc)%pn].timerun);
tppjx+="进程名:"+newthread[(stat+countjc)%pn].threadname+" 到达时间:"+tmp[0]+" 需cpu运行时间:"+tmp[1]+" 已运行时间:"+tmp[2]+"\n";
}
}
pStat1 = (CStatic *)GetDlgItem(IDC_READY2);
pStat1->SetWindowText(tppjx);
//显示当前已逝去时间
tpp.Format("%d",timeout);
pStatTimeout->SetWindowText(tpp);
//显示完成
pStat1 = (CStatic *)GetDlgItem(IDC_CPUDO);
pStat1->SetWindowText("完成");
}
void COSDlg::On32775()
{
// TODO: 在此添加命令处理程序代码
CButton *pButton1,*pButton2,*pButton3,*pButton4;
CEdit *pEdit3,*pEdit4;
pEdit1 = (CEdit*)GetDlgItem(IDC_EDIT2);
pEdit2 = (CEdit *)GetDlgItem(IDC_EDIT3);
pEdit3 = (CEdit*)GetDlgItem(IDC_PRONUM);
pEdit4 = (CEdit *)GetDlgItem(IDC_SLICE);
pEdit1->SetWindowText("5");
pEdit2->SetWindowText("3");
pEdit1->ShowWindow(SW_SHOW);
pEdit2->ShowWindow(SW_SHOW);
pStat1 = (CStatic *)GetDlgItem(IDC_READY1);
pStat1->ShowWindow(SW_HIDE);
pStat1 = (CStatic *)GetDlgItem(IDC_READY2);
pStat1->SetWindowText("");
pStat1->ShowWindow(SW_HIDE);
pStat1 = (CStatic *)GetDlgItem(IDC_OVER1);
pStat1->ShowWindow(SW_HIDE);
pStat1 = (CStatic *)GetDlgItem(IDC_OVER2);
pStat1->SetWindowText("");
pStat1->ShowWindow(SW_HIDE);
pStat1 = (CStatic *)GetDlgItem(IDC_CPUDO);
pStat1->SetWindowText("空闲");
pStat1 = (CStatic *)GetDlgItem(IDC_RUNOUT);
pStat1->SetWindowText("0");
pButton1 = (CButton *)GetDlgItem(IDC_BUTTON1);
pButton2 = (CButton *)GetDlgItem(IDC_BUTTON2);
pButton3 = (CButton *)GetDlgItem(IDC_BUTTON3);
pButton4 = (CButton *)GetDlgItem(IDC_BUTTON4);
pButton1->ShowWindow(SW_SHOW);
if(pEdit3!=NULL)
pEdit3->ShowWindow(SW_SHOW);
if(pEdit4!=NULL)
pEdit4->ShowWindow(SW_SHOW);
if (pButton2!=NULL)
delete pButton2;
if (pButton3!=NULL)
delete pButton3;
if (pButton4!=NULL)
delete pButton4;
if(pn!=0)
{
for(int countjc=0; countjc<pn; countjc++)
{
for(int j=0;j<3;j++)
{
pro[countjc][j]->GetDlgItem(211+3*countjc+j);
if (pro[countjc][j]!=NULL)
delete pro[countjc][j];
}
}
for (int i=0;i<3;i++)
{
ppStat[i]->GetDlgItem(4000+i);
if (ppStat[i]!=NULL)
delete ppStat[i];
}
for (int i=0;i<pn;i++)
{
pStat[i]->GetDlgItem(300+i);
if (pStat[i]!=NULL)
delete pStat[i];
}
}
pn=0;
slice=0;
front=rear=0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -