银行家算法 死锁避免 可视化 MFC


本系统是为了能够使操作系统的进程能够正确地共享资源,并且不会因为共享资源而陷入死锁,对此,采用银行家算法。把操作系统看作是银行家,操作系统管理的资源相当于银行家管理的资金,进程向操作系统请求分配资源相当于用户向银行家贷款。操作系统按照银行家制定的规则为进程分配资源,当进程首次申请资源时,要测试该进程对资源的最大需求量,如果系统现存的资源可以满足它的最大需求量则按当前的申请量分配资源,否则就推迟分配。当进程在执行中继续申请资源时,先测试该进程已占用的资源数与本次申请的资源数之和是否超过了该进程对资源的最大需求量。若超过则拒绝分配资源,若没有超过则再测试系统现存的资源能否满足该进程尚需的最大资源量,若能满足则按当前的申请量分配资源,否则也要推迟分配
资源截图
代码片段和文件信息
// Banker.cpp : Defines the class behaviors for the application.
//

#include “stdafx.h“
#include “Banker.h“
#include “BankerDlg.h“
#include “initdlg.h“

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern int ResourceNumber;
extern int ProcessNumber;
/////////////////////////////////////////////////////////////////////////////
// CBankerApp

BEGIN_MESSAGE_MAP(CBankerApp CWinApp)
//{{AFX_MSG_MAP(CBankerApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
//    DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP CWinApp::onhelp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBankerApp construction

CBankerApp::CBankerApp()
{
// TODO: add construction code here
// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CBankerApp object

CBankerApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CBankerApp initialization

BOOL CBankerApp::InitInstance()
{
AfxEnableControlContainer();

// Standard initialization
// If you are not using these features and wish to reduce the size
//  of your final executable you should remove from the following
//  the specific initialization routines you do not need.

#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
InitDlg InitDlg;
int respone = InitDlg.DoModal();
if(respone == IDOK)
{
ResourceNumber = InitDlg.m_Init_ResourceNumber;
ProcessNumber = InitDlg.m_Init_ProcessNumber;
CBankerDlg dlg;
m_pMainWnd = &dlg;
SetDialogBkColor(RGB(192192192)RGB(00255));
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
//  dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
//  dismissed with Cancel
}

}

// Since the dialog has been closed return FALSE so that we exit the
//  application rather than start the application‘s message pump.
return FALSE;
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件         33  2010-07-07 09:15  Allocation.txt

     文件          5  2010-07-07 10:14  Available.txt

     文件         34  2010-07-07 09:16  Max.txt

     文件         20  2010-07-11 22:00  ReadMe.txt

     文件         33  2010-07-07 09:15  BankerAllocation.txt

     文件          5  2010-07-07 10:14  BankerAvailable.txt

     文件      38780  2010-07-18 21:29  BankerBanker.aps

     文件       2044  2010-07-18 21:29  BankerBanker.clw

     文件       2390  2010-07-05 08:29  BankerBanker.cpp

     文件       5593  2010-07-05 09:50  BankerBanker.dsp

     文件        564  2010-07-04 14:55  BankerBanker.dsw

     文件       1324  2010-07-04 14:45  BankerBanker.h

     文件     492544  2010-07-18 21:29  BankerBanker.ncb

     文件      49664  2010-07-18 21:29  BankerBanker.opt

     文件       2500  2010-07-18 21:29  BankerBanker.plg

     文件      11048  2010-07-18 21:29  BankerBanker.rc

     文件      24393  2010-07-07 13:55  BankerBankerDlg.cpp

     文件       2367  2010-07-07 09:37  BankerBankerDlg.h

     文件     159861  2010-07-18 21:29  BankerDebugBanker.exe

     文件     315764  2010-07-18 21:29  BankerDebugBanker.ilk

     文件      39807  2010-07-18 21:29  BankerDebugBanker.obj

     文件    5568864  2010-07-18 21:29  BankerDebugBanker.pch

     文件     435200  2010-07-18 21:29  BankerDebugBanker.pdb

     文件       4320  2010-07-18 21:29  BankerDebugBanker.res

     文件     131863  2010-07-18 21:29  BankerDebugBankerDlg.obj

     文件      25101  2010-07-18 21:29  BankerDebugfont.obj

     文件      20542  2010-07-18 21:29  BankerDebugInitDlg.obj

     文件     147814  2010-07-18 21:29  BankerDebugmsflexgrid.obj

     文件      17643  2010-07-18 21:29  BankerDebugpicture.obj

     文件      13796  2010-07-18 21:29  BankerDebug
owcursor.obj

............此处省略26个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)