进程和线程与调度.ppt
Session2:TestingWindowsCE.NETAlanPage,MicrosoftTherearetwoprimaryarchitecturalchoicesforanOStohandlePriorityinversioninasystem:SingleLevelandFullyNested.IntheFullyNestedModetheOSwillwalkthroughallthreadsblockedandkeepboostingeachoneuntilthehighprioritythreadcanrun.Thispreventsanentireclassofdeadlocks.UnfortunatelyitalsomeansanO(n)operationwithpre-emptionturnedoffwhiletheschedulerfiguresouthowtogeteverythingunblockedtokeepthingsgoing.Thisisamajorproblemforreal-timesystemsthatneeddeterministicresponsetimes.Inordertosupporthardreal-timesystemsWindowsCEV3.0andlaterswitchedtousingaSingleLevelhandlingofpriorityinversion.ThatistheOSwillboostonlyonethreadtoreleaseablock.Itisthereforetheresponsibilityofthedevelopertostructurecodesuchthatdeadlocksareavoided.进程线程调度2.2进程和线程与调度进程线程调度2.2进程和线程与调度进程(process)定义:是一个具有一定独立功能的程序在一个数据集合上的一次动态执行过程。它是系统进行资源分配和调度的一个独立单位。进程通常由三部分组成:程序、数据集合、进程控制块PCB(ProcessControlBlock)进程特点:动态性独立性并发行结构化123进程概述进程概述进程与程序的联系:程序是构成进程的两个组成部分之一。一个进程的运行目标是执行它对应的程序。进程与程序的区别:程序是静态的,进程是动态的。进程有创建、执行及撤销而消亡的生命周期,程序只是一个文件,存在于某种介质上。一个程序可对应多个进程,但是一个进程只能对应一个程序。WindowsCE(5.0)最多只支持32个进程同时运行。每个进程占据32MB的虚拟地址空间,也被称为一个Slot。在系统启动的时候,默认会启动四个进程,NK.EXE,FILESYS.EXE,GWES.EXE及DEVICE.EXE。WindowsCE进程WindowsCE进程WindowsCE的进程也不支持环境变量(EnvironmentVariable)和当前目录。如果没有明确指明可执行文件的路径,那么WindowsCE会按照如下的顺序搜索:首先查找“\Windows”目录查找根目录(“\”)OEM所指定的搜索目录(“HKEY_LOCAL_MACHINE\Loader\SystemPath”)例如:如果MyApp.exe的同一目录中存在MyFile.tex,那么下面的代码都是不正确的。_wfopen(L”%WINDOWS%\\MyFile.txt,L”w”);_wfopen(L”MyFile.txt”,L”w”);WindowsCE进程一种解决方案TCHARszBuf[MAX_PATH];DWORDdwPathLen;//得到当前程序可执行文件的完整路径dwPathLen=GetModuleFileName(NULL,szBuf,MAX_PATH);if(!dwPathLen){return-1;}//除去文件名while(szBuf[--dwPathLen]!=‘\\’);szBuf[dwPathLen+1]=NULL;//拼接