2 bingfenghuiyipp bingfenghuiyipp 于 2016.05.10 09:48 提问

处理机调度算法实验报告

// Thread.cpp : 实现文件
//

#include "stdafx.h"
#include "HW.h"
#include "Thread.h"

#include "Queue.h"
#include "ThreadManager.h"

CThread::CThread(int time)
:m_thread(NULL),
m_leaveTime(time),
m_totalTime(time),
m_queue(NULL),
m_selected(FALSE)
{

}
IMPLEMENT_DYNAMIC(CThread, CStatic)

CThread::~CThread()
{
}

BEGIN_MESSAGE_MAP(CThread, CStatic)
//{{AFX_MSG_MAP(CThread)
ON_WM_PAINT()
ON_WM_ERASEBKGND()
ON_COMMAND(THREAD_EXIT, OnThreadExit)
ON_COMMAND(THREAD_TIMEOUT, OnThreadTimeOut)
ON_COMMAND(THREAD_RUN, OnRun)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

// CThread 消息处理程序

void CThread::OnPaint()
{
CPaintDC dc(this);
CString str;
str.Format("%d",m_leaveTime);
dc.SetBkMode(TRANSPARENT);
dc.TextOut(0,0,str);
}

BOOL CThread::OnEraseBkgnd(CDC* pDC)
{
COLORREF m_color(RGB(0,255,0));
CRect rect;
CBrush foreBrush(m_color);
GetWindowRect(&rect);
ScreenToClient(rect);
pDC->FillRect(rect,&foreBrush);
foreBrush.DeleteObject();
CBrush *borderBrush=NULL;
if(m_selected)
borderBrush=new CBrush(RGB(255,0,0));
else
borderBrush=new CBrush(RGB(0,0,0));
pDC->FrameRect(rect,borderBrush);
borderBrush->DeleteObject();
delete borderBrush;
return TRUE;
}

UINT CThread::ThreadFunction(LPVOID pParam)
{
CThread pThis=(CThread)pParam;
while(pThis->m_leaveTime>0)
{
if(pThis->m_spaceTime<=0)
{
pThis->PostMessage(WM_COMMAND,THREAD_TIMEOUT,0);
pThis->Wait();
}
pThis->Invalidate();
Sleep(1000);
pThis->m_leaveTime--;
pThis->m_spaceTime--;
pThis->Invalidate();
}
pThis->PostMessage(WM_COMMAND,THREAD_EXIT,0);
return 0;
}

void CThread::Kill()
{
TerminateThread(*m_thread,0);
PostMessage(WM_COMMAND,THREAD_EXIT,0);
}

void CThread::Wait()
{
m_thread->SuspendThread();
PostMessage(WM_COMMAND,THREAD_WAIT,0);
}
void CThread::OnRun()
{
if(m_thread==NULL)
{
m_thread=AfxBeginThread(ThreadFunction,this);
}
else
{
m_thread->ResumeThread();
}
}
int CThread::Create(CWnd * pWnd)
{
return CStatic::Create(NULL,WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER
,CRect(0,0,0,0),pWnd);
}

void CThread::SetQueue(Queue *queue)
{
m_queue=queue;
}

void CThread::OnThreadTimeOut()
{
Sleep(10);
m_queue->OnThreadTimeOut();
}

void CThread::OnThreadExit()
{
m_queue->OnThreadExit();
}

void CThread::SetSpaceTime(int time)
{
m_spaceTime=time;
}

void CThread::Selected(BOOL sel)
{
m_selected=sel;
}

不知道代码意思,没法写流程图
谁帮我解释解释呗,谢了!

2个回答

caozhy
caozhy   Ds   Rxr 2016.05.10 09:57

这是mfc框架下多线程并发调用的代码,用传统的流程图很难表示,最好用活动图来表示。

CSDNXIAON
CSDNXIAON   2016.05.10 09:52

数据挖掘实验报告-关联规则算法实验
----------------------同志你好,我是CSDN问答机器人小N,奉组织之命为你提供参考答案,编程尚未成功,同志仍需努力!

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!